Mono Class Library: System.Xml NamespaceSystem.Xml.NameTable Class |
See Also: NameTable Members
System.Object
System.Xml.XmlNameTable
System.Xml.NameTable
|
This class is multi-read threadsafe but not threadsafe for read/write.
Only a single instance of any given string is stored even if the string is added multiple times to the table.
Using this class provides an efficient means for an XML parser to use the same string object for all repeated element and attribute names in an XML document. If the same object is used for all repeated names, the efficiency of name comparisons is increased by allowing the names to be compared using object comparisons rather than string comparisons.
Note:[Edit]This class implements a single-threaded System.Xml.XmlNameTable .
This class is used internally by the System.Xml.XmlNamespaceManager, System.Xml.XmlParserContext, and System.Xml.XmlTextReader classes to store element and attribute names.
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
Namespace: System.Xml
Assembly: System.Xml (in System.Xml.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0