Share via


GetBaseUri (Compact 2013)

3/26/2014

This interface returns the base URI of the token, if applicable.

Syntax

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

Arguments

  • ppwszBaseUri
    [out] The base URI of the token
  • pcwchBaseUri
    [out] The size of the string that contains the base URI

Return Value

Returns S_OK if no error is generated.

Remarks

The base URI describes the origin of the nodes. If no base URI for the nodes is 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 frequently the case when you use streaming APIs such as ReadValueChunk. For example, if you have an element node that contains text content which includes an entity reference:

<item>1234&ref1;5678</item>

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 as follows:

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

If the entity is only text without any 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 that 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 in which 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 information. The granularity of base URI information in that specification applies to this property.

Note

The pointer that is returned by GetBaseUri is only valid until you move the reader to another node. When you move the reader to another node, XmlLite can reuse the memory referenced by the pointer. Therefore, you should not use the pointer after you call 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.

See Also

Reference

IXmlReader Methods
ReadValueChunk
ResolveUri
IXmlResolver
IXmlReader Properties
Error Codes