次の方法で共有


NameTable クラス

シングルスレッド XmlNameTable を実装します。

この型のすべてのメンバの一覧については、NameTable メンバ を参照してください。

System.Object
   System.Xml.XmlNameTable
      System.Xml.NameTable

Public Class NameTable
   Inherits XmlNameTable
[C#]
public class NameTable : XmlNameTable
[C++]
public __gc class NameTable : public XmlNameTable
[JScript]
public class NameTable extends XmlNameTable

スレッドセーフ

この型の public static (Visual Basicでは Shared) のすべてのメンバは、マルチスレッド操作で安全に使用できます。インスタンスのメンバの場合は、スレッドセーフであるとは限りません。

解説

XmlDocumentXmlReader などのクラスは、内部的に NameTable クラスを使用して、属性名および要素名を格納します。要素名または属性名が複数回 XML ドキュメントに出現した場合は、 NameTable に 1 回だけ格納されます。

名前は、共通言語ランタイム オブジェクト型として格納されます。これにより、負荷のかかる文字列比較ではなく、これらの文字列でオブジェクト比較を実行できます。これらの文字列オブジェクトは " atomized strings " として参照されます。

使用例

[Visual Basic, C#, C++] 2 つの要素名を比較する例を次に示します。

 
'Create the reader.
Dim rdr as XmlTextReader = new XmlTextReader("book.xml")

Dim nt as NameTable = new NameTable()
Dim name as String = nt.Add("book")

while (rdr.Read())
end while
if rdr.NameTable.Get("book") is name
  Console.WriteLine("matches!")
end if

[C#] 
//Create the reader.
XmlTextReader rdr = new XmlTextReader("book.xml");

NameTable nt = new NameTable();
String name = nt.Add("book");

while (rdr.Read()){}
if (rdr.NameTable.Get("book") == name)
  Console.WriteLine("matches!");

[C++] 
//Create the reader.
XmlTextReader* rdr = new XmlTextReader(S"book.xml");

NameTable* nt = new NameTable();
String * name = nt -> Add(S"book");

while (rdr -> Read()) {}
if (rdr -> NameTable -> Get(S"book") == name)
  Console::WriteLine(S"matches!");

[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

名前空間: System.Xml

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ, .NET Compact Framework - Windows CE .NET

アセンブリ: System.Xml (System.Xml.dll 内)

参照

NameTable メンバ | System.Xml 名前空間