XmlTextReader.NamespaceURI Propriété

Définition

Obtient l'URI d'espace de noms (tel qu'il est défini dans la spécification relative aux espaces de noms du W3C) du nœud sur lequel le lecteur est placé.

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, le cas échéant, le préfixe et l’URI de l’espace de noms.

#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

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

Notes

À compter de .NET Framework 2.0, nous vous recommandons de créer XmlReader des instances à l’aide de la XmlReader.Create méthode pour tirer parti des nouvelles fonctionnalités.

Cette propriété concerne uniquement les Element nœuds et Attribute .

S’applique à

Voir aussi