Assembly: System.Xml (in system.xml.dll)
Public MustInherit Class XmlNameTable
Dim instance As XmlNameTable
public abstract class XmlNameTable
public ref class XmlNameTable abstract
public abstract class XmlNameTable
public abstract class XmlNameTable
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.
Nell'esempio seguente vengono confrontati due nomi di elementi:
' 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()
// 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();
System.Xml.XmlNameTable
System.Xml.NameTable
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.