Thanks for your attention.
Paul Bacelar.
PS: For information, the xml document is the result of a
XMLHTTP WEBDAV request and it's our dear Exchange2000
which choose the prefixes.
>My problem is:
>I receive a document XML with namespaces.
>I want to use the method "selectSingleNode" of
>IXMLDOMDocument2 interface to recover a precise node.
>All functions well except that the way that I must use,
>apparently, a path with the prefixes defined in the
>document and not the namespaces.
>Example:
><?xml version="1.0 "? >
> < a:multistatus xmlns:"DAV: ">
> < a:response >
> < a:propstat/>
> </a:response >
> </a:multistatus >
>selectSingleNode(_bstr_t
>(L"a:multistatus/a:response/a:propstat")) is OK
>selectSingleNode(_bstr_t
>(L"DAV:multistatus/DAV:response/DAV:propstat")) is not OK.
>In short, how I can recover the prefix used for a given
>namespace.
>
Here is a suggestion:
// retrieve root element of the document
IXMLDOMElement* documentElement = NULL;
hr = xmlDoc->get_documentElement(&documentElement);
// retrieve attributes of the root element
IXMLDOMNamedNodeMap* nodeMap = NULL;
hr = xmlDoc->get_attributes(&nodeMap);
// iterate through all attributes
long length = 0;
hr = xmlDoc->get_length(&length);
for (long i = 0; i < length; i++) {
IXMLDOMNode* currentAttribute = NULL;
hr = nodeMap->get_item(i, ¤tAttribute);
// retrieve currentAttribute prefix
BSTR prefix = NULL
hr = currentAttribute->get_prefix(&prefix);
// retrieve attribute base name
BSTR baseName = NULL
hr = currentAttribute->get_baseName(&baseName);
// retrieve attribute text
BSTR nodeText = NULL
hr = currentAttribute->get_text(&nodeText);
// if prefix == "xmlns" and nodeText == <your_namespace>, then the prefix you're looking for is the attribute baseName
// you can also create a lookup table to map namespace to prefix.
}
--
Samer Boshra, Microsoft Visual C++ Team
This posting is provided "AS IS" with no warranties, and confers no rights. Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm