Editare

Partajați prin


NameTable Class

Definition

Implements a single-threaded XmlNameTable.

public ref class NameTable : System::Xml::XmlNameTable
public class NameTable : System.Xml.XmlNameTable
type NameTable = class
    inherit XmlNameTable
Public Class NameTable
Inherits XmlNameTable
Inheritance
NameTable

Examples

The following example compares two element names.

NameTable^ nt = gcnew NameTable;
Object^ book = nt->Add( "book" );
Object^ price = nt->Add( "price" );

// Create the reader.
XmlReaderSettings ^ settings = gcnew XmlReaderSettings;
settings->NameTable = nt;
XmlReader^ reader = XmlReader::Create( (String^)"books.xml", settings );
reader->MoveToContent();
reader->ReadToDescendant( "book" );
if ( System::Object::ReferenceEquals( book, reader->Name ) )
{
   
   // Do additional processing.
}

NameTable nt = new NameTable();
object book = nt.Add("book");
object price = nt.Add("price");

// Create the reader.
XmlReaderSettings settings = new XmlReaderSettings();
settings.NameTable = nt;
XmlReader reader = XmlReader.Create("books.xml", settings);

reader.MoveToContent();
reader.ReadToDescendant("book");

 if (System.Object.ReferenceEquals(book, reader.Name)) {
     // Do additional processing.
 }

   Dim nt As NameTable  = New NameTable()
   Dim book As object = nt.Add("book")
   Dim price As object = nt.Add("price")

   ' Create the reader.
   Dim settings As XmlReaderSettings = New XmlReaderSettings()
   settings.NameTable = nt
   Dim reader As XmlReader = XmlReader.Create("books.xml", settings)

   reader.MoveToContent()
   reader.ReadToDescendant("book")

    If (System.Object.ReferenceEquals(book, reader.Name)) 
        ' Do additional processing.
    End If

Remarks

Several classes, such as XmlDocument and XmlReader, use 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.

Constructors

NameTable()

Initializes a new instance of the NameTable class.

Methods

Add(Char[], Int32, Int32)

Atomizes the specified string and adds it to the NameTable.

Add(String)

Atomizes the specified string and adds it to the NameTable.

Equals(Object)

Determines whether the specified object is equal to the current object.

(Inherited from Object)
Get(Char[], Int32, Int32)

Gets the atomized string containing the same characters as the specified range of characters in the given array.

Get(String)

Gets the atomized string with the specified value.

GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetType()

Gets the Type of the current instance.

(Inherited from Object)
MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
ToString()

Returns a string that represents the current object.

(Inherited from Object)

Applies to