Classe XmlNameTable (System.Xml)

Cambia visualizzazione:
ScriptFree
Riferimento a .NET Framework
Classe XmlNameTable

Tabella degli oggetti stringa suddivisi in elementi di base.

Spazio dei nomi: System.Xml
Assembly: System.Xml (in system.xml.dll)

Sintassi

Visual Basic - (Dichiarazione)
Public MustInherit Class XmlNameTable
Visual Basic (Utilizzo)
Dim instance As XmlNameTable

C#
public abstract class XmlNameTable
C++
public ref class XmlNameTable abstract
J#
public abstract class XmlNameTable
JScript
public abstract class XmlNameTable
Note

Varie classi, quali XmlDocument e XmlReader, utilizzano internamente la classe XmlNameTable per memorizzare i nomi di attributi e di elementi. Quando il nome di un elemento o di un attributo ricorre più volte in un documento XML, viene memorizzato una sola volta in XmlNameTable.

I nomi vengono memorizzati come tipi di oggetti CLR (Common Language Runtime). In questo modo è possibile confrontare gli oggetti sulle stringhe invece che eseguire l'operazione più complessa del confronto tra le stringhe. Gli oggetti stringa sono definiti "atomizedstrings".

La classe XmlNameTable viene implementata nella classe NameTable.

Esempio

Nell'esempio seguente vengono confrontati due nomi di elementi:

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

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


Gerarchia di ereditarietà

System.Object
  System.Xml.XmlNameTable
     System.Xml.NameTable
Codice thread safe

I membri statici pubblici (Shared in Visual Basic) di questo tipo sono validi per le operazioni multithreading. I membri di istanza non sono garantiti come thread safe.
Piattaforme

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile per Pocket PC, Windows Mobile per Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework non supporta tutte le versioni di ciascuna piattaforma. Per un elenco delle versioni supportate, vedere Requisiti di sistema.

Informazioni sulla versione

.NET Framework

Supportato in: 2.0 1.1 1.0

.NET Compact Framework

Supportato in: 2.0 1.0
Vedere anche