XmlNameTable 類別

定義

原子化字串物件的資料表。

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

範例

下列範例會比較兩個元素名稱。


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

備註

數個類別,例如 XmlDocumentXmlReader ,會在 XmlNameTable 內部使用 類別來儲存屬性和元素名稱。 當項目或屬性名稱在 XML 文件中出現多次時,它只會在 XmlNameTable 中儲存一次。

這些名稱會儲存為 Common Language Runtime (CLR) 物件型別。 這可讓您對這些字串進行物件比較,而不需要更耗費資源的字串比較。 這些字串物件稱為「不可部分完成的字串」。

XmlNameTable 是在 類別中實作 NameTable

建構函式

XmlNameTable()

初始化 XmlNameTable 類別的新執行個體。

方法

Add(Char[], Int32, Int32)

在衍生類別中覆寫時,原子化指定的字串,並將它加入至 XmlNameTable

Add(String)

在衍生類別中覆寫時,原子化指定的字串,並將它加入至 XmlNameTable

Equals(Object)

判斷指定的物件是否等於目前的物件。

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

在衍生類別中覆寫時,取得包含相同字元的原子化字串做為指定陣列中的指定字元範圍。

Get(String)

在衍生類別中覆寫時,取得包含相同值的原子化字串做為指定的字串。

GetHashCode()

做為預設雜湊函式。

(繼承來源 Object)
GetType()

取得目前執行個體的 Type

(繼承來源 Object)
MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
ToString()

傳回代表目前物件的字串。

(繼承來源 Object)

適用於

另請參閱