XmlEntityReference.BaseURI Property

 

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

Namespace:   System.Xml
Assembly:  System.Xml (in System.Xml.dll)

public override string BaseURI { get; }

Property Value

Type: System.String

The location from which the node was loaded.

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).

The following example displays information on entity reference node, including its base URI.

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);
  }
}

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>.

.NET Framework
Available since 1.1
Return to top
Show: