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在 .

這些名稱會以共通語言執行時(CLR)物件型別儲存。 這讓你能對這些字串進行物件比較,而不必花更多錢的字串比較。 這些字串物件稱為「原子化字串」。

XmlNameTable 在類別 NameTable 中實作。

建構函式

名稱 Description
XmlNameTable()

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

方法

名稱 Description
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)

適用於

另請參閱