XmlNodeReader.BaseURI Właściwość

Definicja

Pobiera podstawowy identyfikator URI bieżącego węzła.

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

Wartość właściwości

String

Podstawowy identyfikator URI bieżącego węzła.

Przykłady

Poniższy przykład analizuje plik i wyświetla podstawowy identyfikator URI każdego z węzłów.

#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

W przykładzie użyto pliku , uri.xmljako danych wejściowych.


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

Plik style.xml zawiera tekst <style>hardcover</style>XML .

Uwagi

Uwaga

W .NET Framework 2.0 zalecaną praktyką jest utworzenie XmlReader wystąpień przy użyciu XmlReaderSettings klasy i Create metody. Dzięki temu można w pełni wykorzystać wszystkie nowe funkcje wprowadzone w .NET Framework. Aby uzyskać więcej informacji, zobacz sekcję Uwagi na stronie referencyjnej XmlReader .

Dokument XML w sieci składa się z fragmentów danych zagregowanych przy użyciu różnych standardowych mechanizmów dołączania W3C i w związku z tym zawiera węzły pochodzące z różnych miejsc. Jednostki DTD są przykładem tego problemu, ale nie jest to ograniczone do jednostek DTD. Podstawowy identyfikator URI informuje o tym, skąd pochodzą te węzły. Jeśli nie ma podstawowego identyfikatora URI dla zwracanych węzłów (na przykład zostały one przeanalizowane z ciągu w pamięci), zwracany jest ciąg.Empty.

Dotyczy