分享

XmlNameTable 类 (System.Xml)

 龙门过客栈 2017-11-17

XmlNameTable 类

.NET Framework (current version)
 

原子化字符串对象表。

命名空间:   System.Xml
程序集:  System.Xml(位于 System.Xml.dll)

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

Public MustInherit Class XmlNameTable

名称说明
System_CAPS_protmethodXmlNameTable()

初始化 XmlNameTable 类的新实例。

名称说明
System_CAPS_pubmethodAdd(Char(), Int32, Int32)

当在派生类中重写,将指定的字符串原子化并将其添加到 XmlNameTable

System_CAPS_pubmethodAdd(String)

当在派生类中重写,将指定的字符串原子化并将其添加到 XmlNameTable

System_CAPS_pubmethodEquals(Object)

确定指定的对象是否等于当前对象。(继承自 Object。)

System_CAPS_protmethodFinalize()

在垃圾回收将某一对象回收前允许该对象尝试释放资源并执行其他清理操作。(继承自 Object。)

System_CAPS_pubmethodGet(Char(), Int32, Int32)

当在派生类中重写时获取包含指定的范围内的给定数组中的字符相同的字符的原子化的字符串。

System_CAPS_pubmethodGet(String)

当在派生类中重写时获取包含与指定的字符串相同的值的原子化的字符串。

System_CAPS_pubmethodGetHashCode()

作为默认哈希函数。(继承自 Object。)

System_CAPS_pubmethodGetType()

获取当前实例的 Type(继承自 Object。)

System_CAPS_protmethodMemberwiseClone()

创建当前 Object 的浅表副本。(继承自 Object。)

System_CAPS_pubmethodToString()

返回表示当前对象的字符串。(继承自 Object。)

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

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

XmlNameTable 在中实现 NameTable 类。

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

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

通用 Windows 平台
自 8 起可用
.NET Framework
自 1.1 起可用
可移植类库
可移植 .NET 平台 中受支持
Silverlight
自 2.0 起可用
Windows Phone Silverlight
自 7.0 起可用
Windows Phone
自 8.1 起可用

此类型的所有公共静态(Visual Basic 中的 已共享 在 Visual Basic 中)成员都是线程安全的。不保证所有实例成员都是线程安全的。

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多