XmlNameTable 类

原子化字符串对象表。

**命名空间:**System.Xml
**程序集:**System.Xml(在 system.xml.dll 中)

语法

声明
Public MustInherit Class XmlNameTable
用法
Dim instance As XmlNameTable
public abstract class XmlNameTable
public ref class XmlNameTable abstract
public abstract class XmlNameTable
public abstract class XmlNameTable

备注

有些类(如 XmlDocumentXmlReader)在内部使用 XmlNameTable 类存储属性名和元素名。当 XML 文档中多次出现某个元素名或属性名时,该名称在 XmlNameTable 中只存储一次。

这些名称存储为公共语言运行库 (CLR) 对象类型。这使您能够对这些字符串进行对象比较,而不是开销更大的字符串比较。这些字符串对象被称为 atomizedstrings

XmlNameTableNameTable 类中实现。

示例

下面的示例比较两个元素名。

' 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()
// 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();     

继承层次结构

System.Object
  System.Xml.XmlNameTable
     System.Xml.NameTable

线程安全

此类型的任何公共静态(Visual Basic 中的 Shared)成员都是线程安全的,但不保证所有实例成员都是线程安全的。

平台

Windows 98、Windows 2000 SP4、Windows CE、Windows Millennium Edition、Windows Mobile for Pocket PC、Windows Mobile for Smartphone、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1、1.0

.NET Compact Framework

受以下版本支持:2.0、1.0

请参见

参考

XmlNameTable 成员
System.Xml 命名空间
NameTable 类