You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-users@xerces.apache.org by Mihai Matei <mi...@yahoo.com> on 2007/05/14 15:10:02 UTC
getting root attributes when root element is prefixed with namespace
Hi,
I have this xml file:
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<sptm:Template
xmlns:sptm="http://www.test.com/schemas/uc/1.00/sptm"
commandType="shell"
filename="myfile.xml"
id="1"
</sptm:Template>
and I'm trying to retreive the root attribute names/values, filename="myfile.xml" for example.
The following code works if the root element tag is not prefixed with a namespace:
DOMElement* root = pDoc->getDocumentElement();
const XMLCh* attrValue = root->getAttributes()->getNamedItem(X("filename"))->getNodeValue();
what do I need to change for it to work with the namespace?
I tried getNamedItemNS(), didn't work (I guess it would work if the attribute was prefixed).
Then I tried setting root to:
root = dynamic_cast(pDoc->getElementsByTagNameNS(X("http://www.test.com/schemas/uc/1.00/sptm"), X("Template"))->item(0));
This didn't work also.
Any suggestions?
Thanks.
____________________________________________________________________________________
No need to miss a message. Get email on-the-go
with Yahoo! Mail for Mobile. Get started.
http://mobile.yahoo.com/mail
Re: getting root attributes when root element is prefixed with namespace
Posted by Boris Kolpackov <bo...@codesynthesis.com>.
Hi Mihai,
Mihai Matei <mi...@yahoo.com> writes:
> <?xml version="1.0" encoding="UTF-8" standalone="no" ?>
> <sptm:Template
> xmlns:sptm="http://www.test.com/schemas/uc/1.00/sptm"
> commandType="shell"
> filename="myfile.xml"
> id="1"
> </sptm:Template>
>
> [...]
>
> DOMElement* root = pDoc->getDocumentElement();
> const XMLCh* attrValue = root->getAttributes()->getNamedItem(X("filename"))->getNodeValue();
I don't see why this shouldn't work for the XML instance above. Have you
tried to use this code as is? BTW, the second line can be rewritten as:
const XMLCh* attrValue = root->getAttribute(X("filename"));
hth,
-boris
--
Boris Kolpackov
Code Synthesis Tools CC
http://www.codesynthesis.com
Open-Source, Cross-Platform C++ XML Data Binding