public class NameTable : XmlNameTable
Object
XmlNameTable
NameTable
System.Xml
XML
Creates a table that stores unique instances of String objects.
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: This class implements a single-threaded XmlNameTable .
This class is used internally by the XmlNamespaceManager, XmlParserContext, and XmlTextReader classes to store element and attribute names.
]
The following example demonstrates the difference between equal string values and equal String objects using the NameTable class.
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 issunny : sunny
True : False
sunny : sunny
True : True
System.Xml Namespace
NameTable Constructors
NameTable Methods
NameTable.Add(System.String) Method
NameTable.Add(char[], int, int) Method
NameTable.Get(System.String) Method
NameTable.Get(char[], int, int) Method
public NameTable();
Constructs and initializes a new instance of the NameTable class.
System.Xml.NameTable Class, System.Xml Namespace
public override string Add(string key);
Adds the specified String to the table if a String instance with the same value does not already exist in the table.
- key
- The String to add.
key, if it did not exist in the table at the time of the call, or the String instance previously stored in the table with a value equal to key.
Exception Type Condition ArgumentNullException key is null
.
Only a single instance of any given String is stored in the table. If the value of key is already stored in the table, the String instance with that value is returned.[Note: This method overrides System.Xml.XmlNameTable.Add(System.Char[],System.Int32,System.Int32)(
String
).]
System.Xml.NameTable Class, System.Xml Namespace
public override string Add(char[] key, int start, int len);
Adds the String equivalent of a specified subset of a Char array to the table if the string equivalent does not already exist in the table.
- key
- A Char array containing the string to add.
- start
- A Int32 specifying the zero-based index into the array of the first character of the string.
- len
- A Int32 containing the number of characters in the string.
The String equivalent of the specified subset of the Char array that is stored in the table, or System.String.Empty if len is zero.
Exception Type Condition IndexOutOfRangeException start < 0. - or -
start >= key.Length.
- or -
len > key.Length - start.
The above conditions do not cause an exception to be thrown if len = 0.
ArgumentOutOfRangeException len < 0.
Only a single instance of any given String is stored in the table. Calling this method with the same subset (containing the same characters) of any Char array, returns the same instance of the String equivalent.[Note: This method overrides System.Xml.XmlNameTable.Add(System.Char[],System.Int32,System.Int32)(
Char
[],Int32
,Int32
).]
System.Xml.NameTable Class, System.Xml Namespace
public override string Get(string value);
Looks up the value of the specified String in the table.
- value
- The String to look up.
The String instance previously stored in the table with a value equal to value , ornull
if it does not exist.
Exception Type Condition ArgumentNullException value is null
.
Only a single instance of any given String is stored in the table. If the value of value is already stored in the table, the String instance with that value is returned.[Note: This method overrides System.Xml.XmlNameTable.Get(System.Char[],System.Int32,System.Int32)(
String
).]
System.Xml.NameTable Class, System.Xml Namespace
public override string Get(char[] key, int start, int len);
Looks up the String equivalent to a specified subset of a Char array in the table.
- key
- A Char array containing the string to look up.
- start
- A Int32 specifying the zero-based index into the array of the first character of the string.
- len
- A Int32 containing the number of characters in the string.
The String equivalent of the specified subset of the Char array that is stored in the table, ornull
if the equivalent String is not in the table.
Exception Type Condition IndexOutOfRangeException start < 0. - or - start >= key.Length.
- or -
len > key.Length - start.
The above conditions do not cause an exception to be thrown if len = 0.
ArgumentOutOfRangeException len < 0.
Only a single instance of any given String is stored in the table. Calling this method with the same subset (containing the same characters) of any Char array, returns the same instance of the String equivalent, if it exists.[Note: This method overrides System.Xml.XmlNameTable.Get(System.Char[],System.Int32,System.Int32)(
Char
[],Int32
,Int32
).]
System.Xml.NameTable Class, System.Xml Namespace