XmlTextReader.NamespaceURI Proprietà
Definizione
Importante
Alcune informazioni sono relative alla release non definitiva del prodotto, che potrebbe subire modifiche significative prima della release definitiva. Microsoft non riconosce alcuna garanzia, espressa o implicita, in merito alle informazioni qui fornite.
Ottiene l'URI dello spazio dei nomi (come definito nella specifica dello spazio dei nomi W3C) del nodo in cui è posizionato il lettore.
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
Valore della proprietà
URI dello spazio dei nomi del nodo corrente; in caso contrario, una stringa vuota.
Esempio
Nell'esempio seguente viene visualizzato il nome locale di ogni nodo e, se esistono, il prefisso e l'URI dello spazio dei nomi.
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
Nell'esempio viene usato il file , book2.xml, come input.
<book xmlns:bk='urn:samples'>
<title>Pride And Prejudice</title>
<bk:genre>novel</bk:genre>
</book>
Commenti
Note
È consigliabile creare XmlReader istanze usando il XmlReader.Create metodo per sfruttare le nuove funzionalità.
Questa proprietà è rilevante solo per Element i nodi e Attribute .