XmlAttribute.BaseURI Właściwość

Definicja

Pobiera podstawowy identyfikator URI 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

Lokalizacja, z której został załadowany węzeł, lub String.Empty, jeśli węzeł nie ma podstawowego identyfikatora URI. Węzły atrybutów mają ten sam podstawowy identyfikator URI co ich element właściciela. Jeśli węzeł atrybutu nie ma elementu właściciela, BaseURI zwraca wartość String.Empty.

Przykłady

Poniższy przykład przedstawia informacje o węźle atrybutu, w tym jego podstawowy identyfikator URI.

#using <System.Xml.dll>

using namespace System;
using namespace System::IO;
using namespace System::Xml;
int main()
{
   
   //Create the XmlDocument.
   XmlDocument^ doc = gcnew XmlDocument;
   doc->Load( "http://localhost/baseuri.xml" );
   
   //Display information on the attribute node. The value
   //returned for BaseURI is 'http://localhost/baseuri.xml'.
   XmlAttribute^ attr = doc->DocumentElement->Attributes[ 0 ];
   Console::WriteLine( "Name of the attribute:  {0}", attr->Name );
   Console::WriteLine( "Base URI of the attribute:  {0}", attr->BaseURI );
   Console::WriteLine( "The value of the attribute:  {0}", attr->InnerText );
}
using System;
using System.IO;
using System.Xml;

public class Sample
{
  public static void Main()
  {
    //Create the XmlDocument.
    XmlDocument doc = new XmlDocument();
    doc.Load("http://localhost/baseuri.xml");

    //Display information on the attribute node. The value
    //returned for BaseURI is 'http://localhost/baseuri.xml'.
    XmlAttribute attr = doc.DocumentElement.Attributes[0];
    Console.WriteLine("Name of the attribute:  {0}", attr.Name);
    Console.WriteLine("Base URI of the attribute:  {0}", attr.BaseURI);
    Console.WriteLine("The value of the attribute:  {0}", attr.InnerText);
  }
}
Option Explicit
Option Strict

Imports System.IO
Imports System.Xml

Public Class Sample
    
    Public Shared Sub Main()
        'Create the XmlDocument.
        Dim doc As New XmlDocument()
        doc.Load("http://localhost/baseuri.xml")
        
        'Display information on the attribute node. The value
        'returned for BaseURI is 'http://localhost/baseuri.xml'.
        Dim attr As XmlAttribute = doc.DocumentElement.Attributes(0)
        Console.WriteLine("Name of the attribute:  {0}", attr.Name)
        Console.WriteLine("Base URI of the attribute:  {0}", attr.BaseURI)
        Console.WriteLine("The value of the attribute:  {0}", attr.InnerText)
    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

Dokument XML w sieci 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. Polecenie BaseURI informuje o tym, skąd pochodzą te węzły.

Aby uzyskać dodatkowe informacje na BaseURI temat tego, jak zachowuje się on z innymi typami węzłów, zobacz XmlNode.BaseURI.

Ta właściwość jest rozszerzeniem firmy Microsoft do modelu obiektów dokumentów (DOM).

Dotyczy

Zobacz też