XmlTextReader.NamespaceURI Propriedade

Definição

Obtém o URI de namespace (conforme definido na especificação de Namespace do 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

String

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.Xml.dll>

using namespace System;
using namespace System::IO;
using namespace System::Xml;
int main()
{
   XmlTextReader^ reader = nullptr;
   try
   {
      
      // Load the reader with the XML file.
      reader = gcnew 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 {0}", reader->NamespaceURI );
            }
         }
      }
   }
   finally
   {
      if ( reader != nullptr )
            reader->Close();
   }

}
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

Observação

A partir do .NET Framework 2.0, 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