XmlNodeReader.NamespaceURI Właściwość

Definicja

Pobiera identyfikator URI przestrzeni nazw (zdefiniowany w specyfikacji przestrzeni nazw W3C) węzła, na którym znajduje się czytnik.

public:
 virtual property System::String ^ NamespaceURI { System::String ^ get(); };
public override string NamespaceURI { get; }
member this.NamespaceURI : string
Public Overrides ReadOnly Property NamespaceURI As String

Wartość właściwości

String

Identyfikator URI przestrzeni nazw bieżącego węzła; w przeciwnym razie pusty ciąg.

Przykłady

Poniższy przykład przedstawia lokalną nazwę każdego węzła, a jeśli istnieją, prefiks i identyfikator URI przestrzeni nazw.

#using <System.Xml.dll>

using namespace System;
using namespace System::IO;
using namespace System::Xml;
int main()
{
   XmlNodeReader^ reader = nullptr;
   try
   {
      
      //Create and load the XML document.
      XmlDocument^ doc = gcnew XmlDocument;
      doc->LoadXml( "<book xmlns:bk='urn:samples'> "
      "<title>Pride And Prejudice</title>"
      "<bk:genre>novel</bk:genre>"
      "</book>" );
      
      //Load the XmlNodeReader 
      reader = gcnew XmlNodeReader( doc );
      
      //Parse the XML.  If they exist, display the prefix and  
      //namespace URI of each node.
      while ( reader->Read() )
      {
         if ( reader->IsStartElement() )
         {
            if ( reader->Prefix == String::Empty )
                        Console::WriteLine( "<{0}>", reader->LocalName );
            else
            {
               Console::Write( "<{0}:{1}>", reader->Prefix, reader->LocalName );
               Console::WriteLine( " The namespace URI is {0}", reader->NamespaceURI );
            }
         }
      }
   }
   finally
   {
      if ( reader != nullptr )
            reader->Close();
   }

}
using System;
using System.IO;
using System.Xml;

public class Sample
{
  public static void Main()
  {
    XmlNodeReader reader = null;

    try
    {
       //Create and load the XML document.
       XmlDocument doc = new XmlDocument();
       doc.LoadXml("<book xmlns:bk='urn:samples'> " +
                   "<title>Pride And Prejudice</title>" +
                   "<bk:genre>novel</bk:genre>" +
                   "</book>");

       //Load the XmlNodeReader
       reader = new XmlNodeReader(doc);

       //Parse the XML.  If they exist, display the prefix and
       //namespace URI of each node.
       while (reader.Read()){
         if (reader.IsStartElement()){
           if (reader.Prefix==String.Empty)
                    {
                        Console.WriteLine("<{0}>", reader.LocalName);
                    }
                    else
                    {
               Console.Write("<{0}:{1}>", reader.Prefix, reader.LocalName);
               Console.WriteLine(" The namespace URI is " + reader.NamespaceURI);
           }
         }
       }
     }
     finally
     {
        if (reader != null)
          reader.Close();
      }
  }
} // End class
Imports System.IO
Imports System.Xml

Public Class Sample
    Public Shared Sub Main()
        Dim reader As XmlNodeReader = Nothing
        
        Try
            'Create and load the XML document.
            Dim doc As New XmlDocument()
            doc.LoadXml("<book xmlns:bk='urn:samples'> " & _
                       "<title>Pride And Prejudice</title>" & _
                       "<bk:genre>novel</bk:genre>" & _
                       "</book>")
            
            'Load the XmlNodeReader 
            reader = New XmlNodeReader(doc)
            
            'Parse the XML.  If they exist, display the prefix and  
            'namespace URI of each node.
            While reader.Read()
                If reader.IsStartElement() Then
                    If reader.Prefix = String.Empty Then
                        Console.WriteLine("<{0}>", reader.LocalName)
                    Else
                        Console.Write("<{0}:{1}>", reader.Prefix, reader.LocalName)
                        Console.WriteLine(" The namespace URI is " & reader.NamespaceURI)
                    End If
                End If
            End While
        
        Finally
            If Not (reader Is Nothing) Then
                reader.Close()
            End If
        End Try
    End Sub
End Class

Uwagi

Uwaga

W .NET Framework 2.0 zalecaną praktyką jest utworzenie XmlReader wystąpień przy użyciu XmlReaderSettings klasy i Create metody. Dzięki temu można w pełni wykorzystać wszystkie nowe funkcje wprowadzone w .NET Framework. Aby uzyskać więcej informacji, zobacz sekcję Uwagi na stronie referencyjnej XmlReader .

Ta właściwość jest odpowiednia tylko dla Element węzłów i Attribute .

Dotyczy