GetPrefix (Compact 2013)
3/26/2014
This interface returns the namespace prefix of the node on which the reader is currently positioned. If no prefix is available, this interface returns an empty string.
Syntax
HRESULT GetPrefix (
const WCHAR** ppwszPrefix,
UINT* pcwchPrefix
);
Arguments
ppwszPrefix
[out] The prefix of the node that the reader is currently positioned on. The returned string is always NULL-terminated.If no prefix is available, the returned string is empty.
The passed in value cannot be NULL.
pcwchPrefix
[out] The size of the string, in characters, is returned.This value is optional. You can pass NULL for it, and the method will not return a value.
Return Value
Returns S_OK if no error is generated.
Remarks
This method returns the namespace prefix. For example, if you call this method for an element <xyz:abc xmlns:xyz="u://1" />
, it returns "xyz".
Note
The pointer that is returned by GetPrefix 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 ppwszPrefix, you should make a deep copy.
The following code returns the namespace prefix of the current node of the reader:
if (FAILED(hr = pReader->GetPrefix(&pwszPrefix, &cwchPrefix)))
{
wprintf(L"Error getting prefix, error is %08.8lx", hr);
return -1;
}
if (FAILED(hr = pReader->GetLocalName(&pwszLocalName, NULL)))
{
wprintf(L"Error getting local name, error is %08.8lx", hr);
return -1;
}
if (cwchPrefix > 0)
wprintf(L"Element: %s:%s\n", pwszPrefix, pwszLocalName);
else
wprintf(L"Element: %s\n", pwszLocalName);