XmlNamespaceManager(XmlNameTable) XmlNamespaceManager(XmlNameTable) XmlNamespaceManager(XmlNameTable) XmlNamespaceManager(XmlNameTable) Constructor

定義

使用指定的 XmlNamespaceManager 初始化 XmlNameTable 類別的新執行個體。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)

參數

例外狀況

null 被傳送至建構函式。null is passed to the constructor

範例

下列範例會XmlNamespaceManager使用讀取器的名稱資料表來建立。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

備註

名稱資料表是用來查閱前置詞和命名空間。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. 例如,如果使用XmlReader物件的名稱資料表,則在每次讀取之後,可以重複XmlNamespaceManager使用任何推送至名稱資料表的命名空間和前置字串。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.

如需已儘量縮減之字串的詳細資訊,請參閱 XmlNameTableFor more information on atomized strings, see XmlNameTable.

注意

如果您指定現有的名稱資料表,名稱資料表中的任何命名空間都不會自動XmlNamespaceManager加入至。If you specify an existing name table, any namespaces in the name table are not automatically added to XmlNamespaceManager. 您必須使用AddNamespaceRemoveNamespace來新增或移除命名空間。You must use AddNamespace and RemoveNamespace to add or remove namespaces.

適用於

另請參閱