XmlTextReader.NamespaceURI Propriété
Définition
Important
Certaines informations portent sur la préversion du produit qui est susceptible d’être en grande partie modifiée avant sa publication. Microsoft exclut toute garantie, expresse ou implicite, concernant les informations fournies ici.
Obtient l’URI d’espace de noms (tel que défini dans la spécification de l’espace de noms W3C) du nœud sur lequel le lecteur est positionné.
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
Valeur de propriété
URI d’espace de noms du nœud actuel ; sinon, une chaîne vide.
Exemples
L’exemple suivant affiche le nom local de chaque nœud et, s’il existe, l’URI du préfixe et de l’espace de noms.
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
L’exemple utilise le fichier, book2.xmlcomme entrée.
<book xmlns:bk='urn:samples'>
<title>Pride And Prejudice</title>
<bk:genre>novel</bk:genre>
</book>
Remarques
Note
Nous vous recommandons de créer des instances XmlReader à l’aide de la méthode XmlReader.Create pour tirer parti de nouvelles fonctionnalités.
Cette propriété s’applique uniquement aux nœuds et Attribute aux Element nœuds.