Share via


XmlNodeReader.BaseURI Proprietà

Definizione

Ottiene l'URI di base del nodo corrente.

public:
 virtual property System::String ^ BaseURI { System::String ^ get(); };
public override string BaseURI { get; }
member this.BaseURI : string
Public Overrides ReadOnly Property BaseURI As String

Valore della proprietà

URI di base del nodo corrente.

Esempio

Nell'esempio seguente viene analizzato un file e viene visualizzato l'URI di base di ognuno dei nodi.

#using <System.Xml.dll>

using namespace System;
using namespace System::IO;
using namespace System::Xml;
int main()
{
   XmlNodeReader^ reader = nullptr;
   try
   {
      
      //Create and load an XmlDocument.
      XmlDocument^ doc = gcnew XmlDocument;
      doc->Load( "http://localhost/uri.xml" );
      reader = gcnew XmlNodeReader( doc );
      
      //Parse the file and display the base URI for each node.
      while ( reader->Read() )
      {
         Console::WriteLine( "({0}) {1}", reader->NodeType, reader->BaseURI );
      }
   }
   finally
   {
      if ( reader != nullptr )
            reader->Close();
   }

}
using System;
using System.IO;
using System.Xml;

public class Sample
{
  public static void Main()
  {
    XmlNodeReader reader = null;

    try
    {
        //Create and load an XmlDocument.
        XmlDocument doc = new XmlDocument();
        doc.Load("http://localhost/uri.xml");

        reader = new XmlNodeReader(doc);

        //Parse the file and display the base URI for each node.
        while (reader.Read())
        {
            Console.WriteLine("({0}) {1}", reader.NodeType, reader.BaseURI);
         }
     }

     finally
     {
       if (reader!=null)
         reader.Close();
     }
  }
} // End class
Option Explicit
Option Strict

Imports System.IO
Imports System.Xml

Public Class Sample
    
    Public Shared Sub Main()
        Dim reader As XmlNodeReader = Nothing
        
        Try
            'Create and load an XmlDocument.
            Dim doc As New XmlDocument()
            doc.Load("http://localhost/uri.xml")
            
            reader = New XmlNodeReader(doc)
            
            'Parse the file and display the base URI for each node.
            While reader.Read()
                Console.WriteLine("({0}) {1}", reader.NodeType, reader.BaseURI)
            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 , uri.xml, come input.


<!-- XML fragment -->
<!DOCTYPE book [<!ENTITY s SYSTEM "tmp/style.xml">]>
<book genre="novel">
  <title>Pride And Prejudice</title>
  <misc>&s;</misc>
</book>

Il style.xml file contiene il testo <style>hardcover</style>XML .

Commenti

Nota

In .NET Framework 2.0, la procedura consigliata consiste nel creare XmlReader istanze usando la XmlReaderSettings classe e il Create metodo . In questo modo è possibile sfruttare appieno tutte le nuove funzionalità introdotte in .NET Framework. Per altre informazioni, vedere la sezione Osservazioni nella pagina di XmlReader riferimento.

Un documento XML in rete è costituito da blocchi di dati aggregati usando vari meccanismi di inclusione standard W3C e quindi contiene nodi provenienti da posizioni diverse. Le entità DTD sono un esempio di questo, ma questo non è limitato ai DTD. L'URI di base indica da dove provengono questi nodi. Se non è presente alcun URI di base per i nodi restituiti( ad esempio, sono stati analizzati da una stringa in memoria), viene restituito String.Empty.

Si applica a