Export (0) Print
Expand All

NameTable Class

Implements a single-threaded XmlNameTable.

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

public class NameTable : XmlNameTable

The NameTable type exposes the following members.

  NameDescription
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360NameTableInitializes a new instance of the NameTable class.
Top

  NameDescription
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360Add(String)Atomizes the specified string and adds it to the NameTable. (Overrides XmlNameTable.Add(String).)
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360Add(Char[], Int32, Int32)Atomizes the specified string and adds it to the NameTable. (Overrides XmlNameTable.Add(Char[], Int32, Int32).)
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360Equals(Object)Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected methodSupported by Silverlight for Windows PhoneSupported by Xbox 360FinalizeAllows an object to try to free resources and perform other cleanup operations before the Object is reclaimed by garbage collection. (Inherited from Object.)
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360Get(String)Gets the atomized string with the specified value. (Overrides XmlNameTable.Get(String).)
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360Get(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 methodSupported by Silverlight for Windows PhoneSupported by Xbox 360GetHashCodeServes as a hash function for a particular type. (Inherited from Object.)
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360GetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodSupported by Silverlight for Windows PhoneSupported by Xbox 360MemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360ToStringReturns 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.



    string xmlString =
    @"<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.
    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;
    using (XmlReader reader = XmlReader.Create(new StringReader(xmlString), 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.
                }
            }
        }
    }


Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

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

Community Additions

ADD
Show:
© 2014 Microsoft