Gets the base URI of the token, if applicable.

HRESULT GetBaseUri ([out] const WCHAR ** ppwszBaseUri, [out] UINT * pcwchBaseUri);


The base URI of the token.


The size of the string that contains the base URI.

Returns S_OK if no error is generated.

The base URI tells you where the nodes came from. If there is no base URI for the nodes being returned (for example, if the nodes were parsed from an in-memory string), the base URI is an empty string.

When parsing the content of an element, the base URI can change. This is most often the case when using streaming APIs such as ReadValueChunk. For example, suppose you have an element node that contains text content which includes an entity reference:


When positioned on the text 1234, the base URI is reported as the base URI of the document. When positioned on the &ref1; entity reference, the base URI is reported as the resolved location for the entity if the entity contains markup and is external to the document. An example of an entity with markup is:

<!ENTITY ref1 "<a>Hello XML Markup</a>">

If the entity is just text with no markup, the XML parsing continues until the end of the next element is reached (in the previous example, </item>). Therefore, the base URI property is always the same as the base URI for the document. For example, an element that contains the following entity reference (&ref2;) does not have a different base URI for that entity reference:

<!ENTITY ref2 "just some text">

The only time the base URI property for an entity reference that contains only text can be different from the base URI of the document is when the ResolveUri method is called on IXmlResolver.

Another case where the base URI can change during parsing is when an XML document is composed of chunks of data aggregated from Document Type Definitions (DTDs). See the W3C XML specification for more details. The granularity of base URI information in that specification applies to this property.


The pointer returned by GetBaseUri is only valid until you move the reader to another node. When you move the reader to another node, XmlLite may reuse the memory referenced by the pointer. Therefore, you should not use the pointer after calling one of the following methods: Read, MoveToNextAttribute, MoveToFirstAttribute, MoveToAttributeByName, or MoveToElement. Although they do not move the reader, the following two methods will also make the pointer invalid: SetInput and IUnknown::Release. If you want to preserve the value that was returned in ppwszBaseUri, you should make a deep copy.

Header: XmlLite.h

Library: XmlLite.lib

© 2014 Microsoft