Uređivanje

Dijeli putem


XmlEntityReference.BaseURI Property

Definition

Gets the base Uniform Resource Identifier (URI) of the current node.

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

Property Value

The location from which the node was loaded.

Examples

The following example displays information on entity reference node, including its base 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/uri.xml" );
   
   //Display information on the entity reference node.
   XmlEntityReference^ entref = dynamic_cast<XmlEntityReference^>(doc->DocumentElement->LastChild->FirstChild);
   Console::WriteLine( "Name of the entity reference:  {0}", entref->Name );
   Console::WriteLine( "Base URI of the entity reference:  {0}", entref->BaseURI );
   Console::WriteLine( "The entity replacement text:  {0}", entref->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/uri.xml");

    //Display information on the entity reference node.
    XmlEntityReference entref = (XmlEntityReference) doc.DocumentElement.LastChild.FirstChild;
    Console.WriteLine("Name of the entity reference:  {0}", entref.Name);
    Console.WriteLine("Base URI of the entity reference:  {0}", entref.BaseURI);
    Console.WriteLine("The entity replacement text:  {0}", entref.InnerText);
  }
}
Imports System.IO
Imports System.Xml

public class Sample

  public shared sub Main()
  
    'Create the XmlDocument.
    Dim doc as XmlDocument = new XmlDocument()
    doc.Load("http://localhost/uri.xml")
                     
    'Display information on the entity reference node.
    Dim entref as XmlEntityReference =  CType(doc.DocumentElement.LastChild.FirstChild, XmlEntityReference) 
    Console.WriteLine("Name of the entity reference:  {0}", entref.Name)
    Console.WriteLine("Base URI of the entity reference:  {0}", entref.BaseURI)
    Console.WriteLine("The entity replacement text:  {0}", entref.InnerText)
  end sub
end class

The sample uses the file, uri.xml, as input.


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

The style.xml file contains the XML string <style>hardcover</style>.

Remarks

A networked XML document is comprised of chunks of data aggregated using various World Wide Web Consortium (W3C) standard inclusion mechanisms and therefore contains nodes that come from different places. The BaseURI tells you where these nodes came from. If there is no base URI for the nodes being returned (maybe they were parsed from an in-memory string), Empty is returned.

BaseURI walks the node tree looking for entity reference boundaries, so if entities are expanded, this information is not preserved and this property returns the location of the XmlDocument in all cases.

For additional information on BaseURI and how it behaves with other node types, see XmlNode.BaseURI.

This property is a Microsoft extension to the Document Object Model (DOM).

Applies to