NameTable NameTable NameTable NameTable Class

定義

實作單一執行緒的 XmlNameTableImplements 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
繼承

範例

下列範例會比較兩個元素的名稱。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

備註

有數個類別 ( XmlDocument例如XmlReader和) 會NameTable在內部使用類別來儲存屬性和專案名稱。Several classes, such as XmlDocument and XmlReader, use the NameTable class internally to store attribute and element names. 當項目或屬性名稱在 XML 文件中出現多次時,它只會在 NameTable 中儲存一次。When an element or attribute name occurs multiple times in an XML document, it is stored only once in the NameTable.

這些名稱會儲存為 Common Language Runtime (CLR) 物件型別。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.

建構函式

NameTable() NameTable() NameTable() NameTable()

初始化 NameTable 類別的新執行個體。Initializes a new instance of the NameTable class.

方法

Add(Char[], Int32, Int32) Add(Char[], Int32, Int32) Add(Char[], Int32, Int32) Add(Char[], Int32, Int32)

將指定的字串原子化,並將其加入至 NameTableAtomizes the specified string and adds it to the NameTable.

Add(String) Add(String) Add(String) Add(String)

將指定的字串原子化,並將其加入至 NameTableAtomizes the specified string and adds it to the NameTable.

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

判斷指定的物件是否等於目前的物件。Determines whether the specified object is equal to the current object.

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

取得包含與指定陣列中指定字元範圍內的字元相同的字串。Gets the atomized string containing the same characters as the specified range of characters in the given array.

Get(String) Get(String) Get(String) Get(String)

取得具有指定值的原子化字串。Gets the atomized string with the specified value.

GetHashCode() GetHashCode() GetHashCode() GetHashCode()

做為預設雜湊函式。Serves as the default hash function.

(Inherited from Object)
GetType() GetType() GetType() GetType()

取得目前執行個體的 TypeGets the Type of the current instance.

(Inherited from Object)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

建立目前 Object 的淺層複本 (Shallow Copy)。Creates a shallow copy of the current Object.

(Inherited from Object)
ToString() ToString() ToString() ToString()

傳回代表目前物件的字串。Returns a string that represents the current object.

(Inherited from Object)

適用於