XmlNameTable 類別
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
原子化字串物件的資料表。
public ref class XmlNameTable abstract
C#
public abstract class XmlNameTable
type XmlNameTable = class
Public MustInherit Class XmlNameTable
- 繼承
-
XmlNameTable
- 衍生
下列範例會比較兩個元素名稱。
C#
// 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
內部使用 類別來儲存屬性和元素名稱。 當項目或屬性名稱在 XML 文件中出現多次時,它只會在 XmlNameTable
中儲存一次。
這些名稱會儲存為 Common Language Runtime (CLR) 物件型別。 這可讓您對這些字串進行物件比較,而不需要更耗費資源的字串比較。 這些字串物件稱為「不可部分完成的字串」。
XmlNameTable
是在 類別中實作 NameTable 。
Xml |
初始化 XmlNameTable 類別的新執行個體。 |
Add(Char[], Int32, Int32) |
在衍生類別中覆寫時,原子化指定的字串,並將它加入至 |
Add(String) |
在衍生類別中覆寫時,原子化指定的字串,並將它加入至 |
Equals(Object) |
判斷指定的物件是否等於目前的物件。 (繼承來源 Object) |
Get(Char[], Int32, Int32) |
在衍生類別中覆寫時,取得包含相同字元的原子化字串做為指定陣列中的指定字元範圍。 |
Get(String) |
在衍生類別中覆寫時,取得包含相同值的原子化字串做為指定的字串。 |
Get |
做為預設雜湊函式。 (繼承來源 Object) |
Get |
取得目前執行個體的 Type。 (繼承來源 Object) |
Memberwise |
建立目前 Object 的淺層複製。 (繼承來源 Object) |
To |
傳回代表目前物件的字串。 (繼承來源 Object) |
產品 | 版本 |
---|---|
.NET | Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7 |
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8 |
.NET Standard | 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1 |
UWP | 10.0 |