Re: [xml] namespace problem
- From: Emmanuel Rodriguez <emmanuel rodriguez gmail com>
- To: Andreas Wagner <andreaswagner7 gmail com>
- Cc: xml gnome org
- Subject: Re: [xml] namespace problem
- Date: Sun, 3 Jan 2010 12:33:18 +0100
On Sat, Jan 2, 2010 at 6:39 PM, Andreas Wagner
<andreaswagner7 gmail com> wrote:
Hi folks,
i have an xml document like this:
<?xml version="1.0" ...?>
<root xmlns:Value="http://dummies.org">
ÂÂ <header>
ÂÂÂÂÂÂ <variables>
ÂÂÂÂÂÂÂÂÂÂ <...../>
ÂÂÂÂÂÂÂÂÂÂ <...../>
ÂÂÂÂÂÂ </variables>
ÂÂÂÂÂÂ <const>
ÂÂÂÂÂÂÂÂÂÂÂ <.../>
ÂÂÂÂÂÂÂÂÂÂÂ <.../>
ÂÂÂÂÂÂ </const>
ÂÂÂÂÂÂ <parameters>
ÂÂÂÂÂÂÂÂÂÂÂ <param name="xxx">
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ <Value:scalar name="xxx" type="BOOL"/>
ÂÂÂÂÂÂÂÂÂÂÂ </param>
ÂÂÂÂÂÂÂÂÂÂÂ <param name="yyy">
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ <Value:scalar name="yyy" type="BOOL"/>
ÂÂÂÂÂÂÂÂÂÂÂ </param>
ÂÂÂÂÂÂ </parameters>
ÂÂ </header>
ÂÂ <body>
ÂÂ </body>
</root>
I can read the variables and the constants in the header, but when i want to read the Value:scalar name and type i get nothing. I read the correct lines, but the content is empty (thats normal) but the name of this element is "text".
When the current node is param i try to get the values with:
xmlChar *name;
cur = cur->xmlChildrenNode;
if (xmlGetNsProp(cur,(const xmlChar*) "name", (const xmlChar*) "Value"){
ÂÂÂ name = xmlGetNsProp(cur,(const xmlChar*) "name", (const xmlChar*) "Value");
ÂÂÂ printf("name: %s \n,name);
}
The second parameter of xmlGetNsProp has to be the URI of the namespace and not the prefix. Use this instead:
xmlGetNsProp(cur,(const xmlChar*) "name", (const xmlChar*) "
http://dummies.org");
Prefixes in namespaces are arbitrary and not always available (i.e. xmlns="
http://dummies.org" has no prefix yet has a namespace). The only way for matching nodes within the same namespace is to compare the URI. It can be a bit confusing sometimes :)
--
Emmanuel Rodriguez
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]