XmlNameTable 類別

定義

原子化字串物件的資料表。Table of atomized string objects.

public ref class XmlNameTable abstract
public abstract class XmlNameTable
type XmlNameTable = class
Public MustInherit Class XmlNameTable
繼承
XmlNameTable
衍生

範例

下列範例會比較兩個元素的名稱。The following example compares two element names.


// 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;
 XmlReader reader = XmlReader.Create("books.xml", 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.
      }
         
    } 

 }  // End While

// Close the reader.
reader.Close();     

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

備註

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

這些名稱會儲存為 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".

XmlNameTable會在NameTable類別中實作為。XmlNameTable is implemented in the NameTable class.

建構函式

XmlNameTable()

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

方法

Add(Char[], Int32, Int32)

在衍生類別中覆寫時,原子化指定的字串,並將它加入至 XmlNameTableWhen overridden in a derived class, atomizes the specified string and adds it to the XmlNameTable.

Add(String)

在衍生類別中覆寫時,原子化指定的字串,並將它加入至 XmlNameTableWhen overridden in a derived class, atomizes the specified string and adds it to the XmlNameTable.

Equals(Object)

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

(繼承來源 Object)
Get(Char[], Int32, Int32)

在衍生類別中覆寫時,取得包含相同字元的原子化字串做為指定陣列中的指定字元範圍。When overridden in a derived class, gets the atomized string containing the same characters as the specified range of characters in the given array.

Get(String)

在衍生類別中覆寫時,取得包含相同值的原子化字串做為指定的字串。When overridden in a derived class, gets the atomized string containing the same value as the specified string.

GetHashCode()

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

(繼承來源 Object)
GetType()

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

(繼承來源 Object)
MemberwiseClone()

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

(繼承來源 Object)
ToString()

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

(繼承來源 Object)

適用於

另請參閱