NameTable Class

NameTable Class

[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]

Implements a single-threaded XmlNameTable.

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

Namespace:  System.Xml
Assembly:  System.Xml (in System.Xml.dll)

'Declaration
Public Class NameTable _
	Inherits XmlNameTable

The NameTable type exposes the following members.

  NameDescription
Public methodNameTableInitializes a new instance of the NameTable class.
Top

  NameDescription
Public methodAdd(String)Atomizes the specified string and adds it to the NameTable. (Overrides XmlNameTable.Add(String).)
Public methodAdd(Char(), Int32, Int32)Atomizes the specified string and adds it to the NameTable. (Overrides XmlNameTable.Add(Char(), Int32, Int32).)
Public methodEquals(Object)Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before the Object is reclaimed by garbage collection. (Inherited from Object.)
Public methodGet(String)Gets the atomized string with the specified value. (Overrides XmlNameTable.Get(String).)
Public methodGet(Char(), Int32, Int32)Gets the atomized string containing the same characters as the specified range of characters in the given array. (Overrides XmlNameTable.Get(Char(), Int32, Int32).)
Public methodGetHashCodeServes as a hash function for a particular type. (Inherited from Object.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Top

The XmlReader uses the NameTable class internally to store attribute and element names. When an element or attribute name occurs multiple times in an XML document, it is stored only once in the NameTable.

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.


Dim xmlString As String = _
"<catalog>" & _
   "<book id='bk101'>" & _
      "<author>Gambardella, Matthew</author>" & _
      "<title>XML Developer's Guide</title>" & _
      "<genre>Computer</genre>" & _
      "<price>44.95</price>" & _
      "<publish_date>2000-10-01</publish_date>" & _
      "<description>An in-depth look at creating applications " & _
      "with XML.</description>" & _
   "</book>" & _
   "<book id='bk102'>" & _
      "<author>Ralls, Kim</author>" & _
      "<title>Midnight Rain</title>" & _
      "<genre>Fantasy</genre>" & _
      "<price>5.95</price>" & _
      "<publish_date>2000-12-16</publish_date>" & _
      "<description>A former architect battles corporate zombies, " & _
      "an evil sorceress, and her own childhood to become queen " & _
      "of the world.</description>" & _
   "</book>" & _
"</catalog>"


' 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
Using reader As XmlReader = XmlReader.Create(New StringReader(xmlString), 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
End Using


Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Show:
© 2017 Microsoft