XmlTextReader.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; }
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 przedstawia podstawowy identyfikator URI dla każdego węzła.

#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( "http://localhost/baseuri.xml" );
      
      //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()
  {
    XmlTextReader reader = null;

    try
    {
        //Load the reader with the XML file.
        reader = new XmlTextReader("http://localhost/baseuri.xml");

        //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 XmlTextReader = Nothing
      
      Try
         'Load the reader with the XML file.
         reader = New XmlTextReader("http://localhost/baseuri.xml")
         
         '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 , baseuri.xmljako danych wejściowych.


<!-- XML fragment -->
<book genre="novel">
  <title>Pride And Prejudice</title>
</book>

Uwagi

Uwaga

Począwszy od .NET Framework 2.0, zalecamy utworzenie XmlReader wystąpień przy użyciu metody , aby korzystać z XmlReader.Create nowych funkcji.

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), String.Empty zostanie zwrócony.

Dotyczy

Zobacz też