Object Comparison Using XmlNameTable with XmlReader

The XmlNameTable class enables the implementations of the XmlReader class to use pointer comparisons instead of string comparisons when parsing data or performing comparison operations on XML documents. The use of this table gives performance gains to the XmlReader derived classes when comparing and using element and attribute names.

The XmlNameTable is an abstract base class with NameTable as an implementation. The NameTable contains atomized version of element and attribute names, along with namespace URIs and prefixes. If the application is doing a lot of comparison on names, the application can create a NameTable. The user can get the NameTable that the reader is using from the NameTable property of the reader. For a description of atomization, see XmlNameTable Class.

The application can add names to the table with the Add method. The following example shows that comparisons are then done by using the Equals method or == operator, which determines whether the object given in the method call is the same instance as the current object.

Dim cust As Object = reader.NameTable.Add("Customer")
While reader.Read()
   ' The "if" uses efficient pointer comparison.
   If cust Is reader.Name Then
   End If
End While

object cust = reader.NameTable.Add("Customer");
while (reader.Read())
   // The "if" uses efficient pointer comparison.
   if (cust == reader.Name)   

For more information on the methods, see XmlNameTable Members.

See Also

Reading XML with the XmlReader | Current Node Position in XmlReader | Property Settings on XmlReader | Reading Attributes with XmlReader | Reading Element and Attributes Content | Skipping Content with XmlReader | EntityReference Reading and Expansion | Comparing XmlReader to SAX Reader | Reading XML Data with XmlTextReader | Reading Node Trees with XmlNodeReader | Validating XML with XmlValidatingReader | Customized XML Reader Creation | XmlReader Class | XmlReader Members | XmlNodeReader Class | XmlNodeReader Members | XmlTextReader Class | XmlTextReader Members | XmlValidatingReader Class | XmlValidatingReader