XmlTextReader.BaseURI Vlastnost

Definice

Získá základní identifikátor URI aktuálního uzlu.

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

Hodnota vlastnosti

String

Základní identifikátor URI aktuálního uzlu.

Příklady

Následující příklad zobrazí základní identifikátor URI pro každý uzel.

#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

Příklad používá soubor , baseuri.xmljako vstup.


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

Poznámky

Poznámka

Počínaje rozhraním .NET Framework 2.0 doporučujeme vytvářet XmlReader instance pomocí XmlReader.Create metody, abyste mohli využívat nové funkce.

Síťový dokument XML se skládá z bloků dat agregovaných pomocí různých mechanismů zahrnutí standardu W3C, a proto obsahuje uzly, které pocházejí z různých míst. Entity DTD jsou příkladem tohoto příkladu, ale není omezena na identifikátory DTD. Základní identifikátor URI vám řekne, odkud tyto uzly pocházejí. Pokud pro vrácené uzly neexistuje žádný základní identifikátor URI (například byly analyzovány z řetězce v paměti), String.Empty vrátí se.

Platí pro

Viz také