XmlNameTable 类
定义
原子化字符串对象表。Table of atomized string objects.
public ref class XmlNameTable abstract
public abstract class XmlNameTable
type XmlNameTable = class
Public MustInherit Class XmlNameTable
- 继承
-
XmlNameTable
- 派生
示例
下面的示例比较两个元素名称。The following example compares two element names.
// Add the element names to the NameTable.
NameTable nt = new NameTable();
object book = nt.Add("book");
object title = nt.Add("title");
// Create a reader that uses the NameTable.
XmlReaderSettings settings = new XmlReaderSettings();
settings.NameTable = nt;
XmlReader reader = XmlReader.Create("books.xml", settings);
while (reader.Read()) {
if (reader.NodeType == XmlNodeType.Element) {
// Cache the local name to prevent multiple calls to the LocalName property.
object localname = reader.LocalName;
// Do a comparison between the object references. This just compares pointers.
if (book == localname) {
// Add additional processing here.
}
// Do a comparison between the object references. This just compares pointers.
if (title == localname) {
// Add additional processing here.
}
}
} // End While
// Close the reader.
reader.Close();
' Add the element names to the NameTable.
Dim nt As New NameTable()
Dim book As Object = nt.Add("book")
Dim title As Object = nt.Add("title")
' Create a reader that uses the NameTable.
Dim settings As New XmlReaderSettings()
settings.NameTable = nt
Dim reader As XmlReader = XmlReader.Create("books.xml", settings)
While reader.Read()
If reader.NodeType = XmlNodeType.Element Then
' Cache the local name to prevent multiple calls to the LocalName property.
Dim localname As Object = reader.LocalName
' Do a comparison between the object references. This just compares pointers.
If book Is localname Then
' Add additional processing here.
End If
' Do a comparison between the object references. This just compares pointers.
If title Is localname Then
' Add additional processing here.
End If
End If
End While
' Close the reader.
reader.Close()
注解
多个类(如 XmlDocument 和 XmlReader ) XmlNameTable
在内部使用类来存储特性和元素名称。Several classes, such as XmlDocument and XmlReader, use the XmlNameTable
class internally to store attribute and element names. 当 XML 文档中多次出现某个元素名或属性名时,该名称在 XmlNameTable
中只存储一次。When an element or attribute name occurs multiple times in an XML document, it is stored only once in the XmlNameTable
.
这些名称存储为公共语言运行时 (CLR) 对象类型。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".
XmlNameTable
在类中实现 NameTable 。XmlNameTable
is implemented in the NameTable class.
构造函数
XmlNameTable() |
初始化 XmlNameTable 类的新实例。Initializes a new instance of the XmlNameTable class. |
方法
Add(Char[], Int32, Int32) |
当在派生类中被重写时,将指定的字符串原子化并将其添加到 |
Add(String) |
当在派生类中被重写时,将指定的字符串原子化并将其添加到 |
Equals(Object) |
确定指定对象是否等于当前对象。Determines whether the specified object is equal to the current object. (继承自 Object) |
Get(Char[], Int32, Int32) |
当在派生类中被重写时,获取与给定数组中指定范围的字符包含相同字符的原子化字符串。When overridden in a derived class, gets the atomized string containing the same characters as the specified range of characters in the given array. |
Get(String) |
当在派生类中被重写时,获取与指定的字符串包含相同值的原子化字符串。When overridden in a derived class, gets the atomized string containing the same value as the specified string. |
GetHashCode() |
作为默认哈希函数。Serves as the default hash function. (继承自 Object) |
GetType() |
获取当前实例的 Type。Gets the Type of the current instance. (继承自 Object) |
MemberwiseClone() |
创建当前 Object 的浅表副本。Creates a shallow copy of the current Object. (继承自 Object) |
ToString() |
返回表示当前对象的字符串。Returns a string that represents the current object. (继承自 Object) |