Compartir a través de


GetPrefix

 

Gets the namespace prefix of the node that the reader is currently positioned on. If no prefix is available, returns an empty string.

Syntax

  
HRESULT GetPrefix ([out] const WCHAR ** ppwszPrefix, [out] UINT * pcwchPrefix);  

Arguments

ppwszPrefix
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
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 returned by GetPrefix 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 ppwszPrefix, you should make a deep copy.

The following code gets 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);  

Requirements

Header: XmlLite.h

Library: XmlLite.lib

See Also

IXmlReader Methods