XmlTextReader.NamespaceURI Propriedade
Definição
Importante
Algumas informações dizem respeito a um produto pré-lançado que pode ser substancialmente modificado antes de ser lançado. A Microsoft não faz garantias, de forma expressa ou implícita, em relação à informação aqui apresentada.
Obtém o URI do namespace (conforme definido na especificação W3C Namespace) do nó onde 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 de Propriedade
O URI do espaço de nomes do nó atual; caso contrário, uma corda vazia.
Exemplos
O exemplo seguinte mostra o nome local de cada nó e, se existirem, o prefixo e o espaço de nomes URI.
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 ficheiro , book2.xmlcomo entrada.
<book xmlns:bk='urn:samples'>
<title>Pride And Prejudice</title>
<bk:genre>novel</bk:genre>
</book>
Observações
Note
Recomendamos que crie instâncias XmlReader usando o método XmlReader.Create para aproveitar a nova funcionalidade.
Esta propriedade é relevante apenas para Element nós.Attribute