System.Xml.NameTable Class

Implements a single-threaded System.Xml.XmlNameTable.

See Also: NameTable Members

Syntax

public class NameTable : XmlNameTable

Remarks

Several classes, such as System.Xml.XmlDocument and System.Xml.XmlReader, use the NameTable class internally to store attribute and element names. When an element or attribute name occurs multiple times in an XML document, it is stored only once in the NameTable.

The names are stored as common language runtime (CLR) object types. This enables you to do object comparisons on these strings rather than a more expensive string comparison. These string objects are referred to as atomized strings.

Thread Safety

This class is multi-read threadsafe but not threadsafe for read/write.

Example

The following example demonstrates the difference between equal string values and equal string objects using the System.Xml.NameTable class.

C# Example

using System;
using System.Text;
using System.Xml;

class Ntable {

  public static void Main() {

    NameTable nameTable = new NameTable();

    string str1 = "sunny";
    StringBuilder strBuilder = new StringBuilder();
    string str2 = 
      strBuilder.Append("sun").Append("ny").ToString();
    Console.WriteLine( "{0} : {1}",
                       str1, str2 );
    Console.WriteLine( "{0} : {1}",
                       str1 == str2,
                       (Object)str1==(Object)str2 );

    string str3 = nameTable.Add(str1);
    string str4 = nameTable.Add(str2);
    Console.WriteLine( "{0} : {1}",
                       str3, str4 );
    Console.WriteLine( "{0} : {1}",
                       str3 == str4,
                       (Object)str3==(Object)str4 );
  }
}
   

The output is

sunny : sunny

True : False

sunny : sunny

True : True

Requirements

Namespace: System.Xml
Assembly: System.Xml (in System.Xml.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0, 4.0.0.0