XmlValidatingReader.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 analizuje plik i wyświetla podstawowy identyfikator URI każdego węzła.

#using <System.Xml.dll>

using namespace System;
using namespace System::IO;
using namespace System::Xml;
int main()
{
   XmlValidatingReader^ reader = nullptr;
   XmlTextReader^ txtreader = nullptr;
   try
   {
      
      //Create the validating reader.
      txtreader = gcnew XmlTextReader( "http://localhost/uri.xml" );
      reader = gcnew XmlValidatingReader( txtreader );
      reader->ValidationType = ValidationType::None;
      
      //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()
  {
    XmlValidatingReader reader = null;
    XmlTextReader txtreader = null;

    try
    {
        //Create the validating reader.
        txtreader = new XmlTextReader("http://localhost/uri.xml");
        reader = new XmlValidatingReader(txtreader);
        reader.ValidationType = ValidationType.None;

        //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 Strict
Option Explicit

Imports System.IO
Imports System.Xml

Public Class Sample
   
   Public Shared Sub Main()
      Dim reader As XmlValidatingReader = Nothing
      Dim txtreader As XmlTextReader = Nothing
      
      Try
         'Create the validating reader.
         txtreader = New XmlTextReader("http://localhost/uri.xml")
         reader = New XmlValidatingReader(txtreader)
         reader.ValidationType = ValidationType.None
         
         '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

Klasa XmlValidatingReader jest przestarzała w .NET Framework 2.0. Wystąpienie weryfikacji XmlReader można utworzyć przy użyciu XmlReaderSettings klasy i Create metody . Aby uzyskać więcej informacji, zobacz sekcję Uwagi na stronie referencyjnej XmlReader .

Sieciowy dokument XML składa się z fragmentów danych zagregowanych przy użyciu różnych standardowych mechanizmów dołączania konsorcjum World Wide Web Consortium (W3C) i w związku z tym zawiera węzły pochodzące z różnych miejsc. Jednostki definicji typu dokumentu (DTD) są przykładem tej funkcji, 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

Zobacz też