Επεξεργασία

Κοινή χρήση μέσω


XmlNamespaceManager(XmlNameTable) Constructor

Definition

Initializes a new instance of the XmlNamespaceManager class with the specified XmlNameTable.

public:
 XmlNamespaceManager(System::Xml::XmlNameTable ^ nameTable);
public XmlNamespaceManager (System.Xml.XmlNameTable nameTable);
new System.Xml.XmlNamespaceManager : System.Xml.XmlNameTable -> System.Xml.XmlNamespaceManager
Public Sub New (nameTable As XmlNameTable)

Parameters

nameTable
XmlNameTable

The XmlNameTable to use.

Exceptions

null is passed to the constructor.

Examples

The following example creates an XmlNamespaceManager using the name table of the reader.

      XmlTextReader^ reader = gcnew XmlTextReader( "myfile.xml" );
      XmlNamespaceManager^ nsmanager = gcnew XmlNamespaceManager( reader->NameTable );
      nsmanager->AddNamespace( "msbooks", "www.microsoft.com/books" );
      nsmanager->PushScope();
      nsmanager->AddNamespace( "msstore", "www.microsoft.com/store" );
      while ( reader->Read() )
      {
         Console::WriteLine( "Reader Prefix:{0}", reader->Prefix );
         Console::WriteLine( "XmlNamespaceManager Prefix:{0}", nsmanager->LookupPrefix( nsmanager->NameTable->Get( reader->NamespaceURI ) ) );
      }
   }

};
XmlTextReader reader = new XmlTextReader("myfile.xml");
XmlNamespaceManager nsmanager = new XmlNamespaceManager(reader.NameTable);
nsmanager.AddNamespace("msbooks", "www.microsoft.com/books");
nsmanager.PushScope();
nsmanager.AddNamespace("msstore", "www.microsoft.com/store");
while (reader.Read())
{
    Console.WriteLine("Reader Prefix:{0}", reader.Prefix);
    Console.WriteLine("XmlNamespaceManager Prefix:{0}",
    nsmanager.LookupPrefix(nsmanager.NameTable.Get(reader.NamespaceURI)));
}
Dim reader As New XmlTextReader("myfile.xml")
Dim nsmanager As New XmlNamespaceManager(reader.NameTable)
nsmanager.AddNamespace("msbooks", "www.microsoft.com/books")
nsmanager.PushScope()
nsmanager.AddNamespace("msstore", "www.microsoft.com/store")
While reader.Read()
    Console.WriteLine("Reader Prefix:{0}", reader.Prefix)
    Console.WriteLine("XmlNamespaceManager Prefix:{0}",             nsmanager.LookupPrefix(nsmanager.NameTable.Get(reader.NamespaceURI)))
End While

Remarks

The name table is used to look up prefixes and namespaces. An existing name table with pre-atomized strings can be specified in the constructor. There are several advantages in doing so. For example, if the name table of an XmlReader object is used, after each read, any namespace and prefix strings pushed into the name table can be re-used by XmlNamespaceManager.

For more information on atomized strings, see XmlNameTable.

Note

If you specify an existing name table, any namespaces in the name table are not automatically added to XmlNamespaceManager. You must use AddNamespace and RemoveNamespace to add or remove namespaces.

Applies to

See also