XmlNameTable 类
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
原子化字符串对象的表。
public ref class XmlNameTable abstract
public abstract class XmlNameTable
type XmlNameTable = class
Public MustInherit Class XmlNameTable
- 继承
-
XmlNameTable
- 派生
示例
以下示例比较两个元素名称。
// 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 内部使用该类来存储属性和元素名称。 当元素或属性名称在 XML 文档中多次发生时,它只存储在 XML XmlNameTable文档中一次。
名称存储为公共语言运行时 (CLR) 对象类型。 这使你可以对这些字符串执行对象比较,而不是更昂贵的字符串比较。 这些字符串对象称为“原子化字符串”。
XmlNameTable 在类中 NameTable 实现。
构造函数
| 名称 | 说明 |
|---|---|
| XmlNameTable() |
初始化 XmlNameTable 类的新实例。 |
方法
| 名称 | 说明 |
|---|---|
| Add(Char[], Int32, Int32) |
在派生类中重写时,将指定字符串原子化并将其添加到派生类中 |
| Add(String) |
在派生类中重写时,将指定字符串原子化并将其添加到派生类中 |
| Equals(Object) |
确定指定的对象是否等于当前对象。 (继承自 Object) |
| Get(Char[], Int32, Int32) |
在派生类中重写时,获取包含与给定数组中指定字符范围相同的字符的原子化字符串。 |
| Get(String) |
在派生类中重写时,获取包含与指定字符串相同的值的原子化字符串。 |
| GetHashCode() |
用作默认哈希函数。 (继承自 Object) |
| GetType() |
获取当前实例的 Type。 (继承自 Object) |
| MemberwiseClone() |
创建当前 Object的浅表副本。 (继承自 Object) |
| ToString() |
返回一个表示当前对象的字符串。 (继承自 Object) |