XmlTextReader.NamespaceURI Propriedade

Definição

Obtém o URI do espaço de nomes (conforme definido na especificação espaço de nomes W3C) do nó no qual o leitor está posicionado.

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

Valor da propriedade

O URI do namespace do nó atual; caso contrário, uma cadeia de caracteres vazia.

Exemplos

O exemplo a seguir exibe o nome local de cada nó e, se existirem, o prefixo e o URI do namespace.

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

public class Sample {

  public static void Main() {

    XmlTextReader reader = null;

    try {

       // Load the reader with the XML file.
       reader = new XmlTextReader("book2.xml");

       // Parse the file.  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 XmlTextReader = Nothing
        
        Try
            ' Load the reader with the XML file.
            reader = New XmlTextReader("book2.xml")
            
            ' Parse the file.  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

O exemplo usa o arquivo, book2.xmlcomo entrada.


<book xmlns:bk='urn:samples'>
  <title>Pride And Prejudice</title>
  <bk:genre>novel</bk:genre>
</book>

Comentários

Note

Recomendamos que você crie XmlReader instâncias usando o XmlReader.Create método para aproveitar a nova funcionalidade.

Essa propriedade é relevante somente para Element nós Attribute .

Aplica-se a

Confira também