Export (0) Print
Expand All

XmlNode.BaseURI Property

Gets the base URI of the current node.

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

public virtual string BaseURI { get; }

Property Value

Type: System.String
The location from which the node was loaded or String.Empty if the node has no base URI.

A networked XML document is comprised of chunks of data aggregated using various W3C standard inclusion mechanisms and therefore contains nodes that come from different places. The BaseURI tells you where these nodes came from.

The value of this property varies depending on the node type. For example, Document nodes return the location of the XmlDocument object. Nodes which are child nodes of external EntityReference nodes return the location of the entity itself. For example, consider the following XML document:

 <!DOCTYPE item [
 <!ENTITY xyz SYSTEM "a/b.xml">
 ]>
 <item num='123'>&xyz;</item>

where the external entity a/b.xml contains the XML text: <test>123</test>.

If the document is loaded from http://server/mydata.xml, BaseURI returns the following:

NodeType

Name

BaseURI

Attribute

num

http://server/mydata.xml

Document

#document

http://server/mydata.xml

DocumentType

item

http://server/mydata.xml

Entity

xyz

http://server/mydata.xml

Element

item

http://server/mydata.xml

EntityReference

xyz

http://server/mydata.xml

Element

test

http://server/a/b.xml

Text

#text

http://server/a/b.xml

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

As a second example, given the following XML document:

 <!DOCTYPE Mydata SYSTEM "http://localhost/doctype.dtd">
 <baa>&xyz;</baa>

where the DTD file contains the following:

 <!ENTITY xyz <E1>My Data</E1>
 <!ELEMENT baa #PCDATA>
 <!ATTLIST baa attr1 "woof">

If the XML document is loaded from http://localhost/mydata.xml, BaseURI returns the following for each of the nodes:

NodeType

Name

BaseURI

Document

#document

http://localhost/mydata.xml

DocumentType

Mydata

http://localhost/mydata.xml

The XmlDocumentType.SystemId or XmlDocumentType.PublicId properties can be used to identify where the DTD file was loaded from.

Element

baa

http://localhost/mydata.xml

Entity

xyz

http://localhost/doctype.dtd

EntityReference

xyz

http://localhost/mydata.xml

Attribute

woof

http://localhost/mydata.xml

NoteNote:

The base URI of a default attribute is the same as the base URI of the element to which they belong.

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

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC, Xbox 360, Zune

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 3.5, 2.0, 1.0

XNA Framework

Supported in: 3.0, 2.0, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft