Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > Please help extract attributes from root node.

Reply
Thread Tools

Please help extract attributes from root node.

 
 
RichardHatcher.com@gmail.com
Guest
Posts: n/a
 
      06-08-2006
I am writing C code using xpath to extract some data from a XML
document. The file uses namespaces, but the name spaces are all listed
in the root node of the file as attributes. I want to extract all the
attributes, so that I can register the namespaces. The document looks
like:

<?xml version="1.0" encoding="UTF-8" ?>
<ConfigDataFile xmlns:SRI="SRI" xmlns:SIW="SIW" xmlns:QBQ="QBQ"
xmlns:VLD="VLD" xmlnssi="http://www.mstsc.com/schema"
xsi:schemaLocation="birdflu.xsd">
<SIW:SIW>
<SIW:herewelive apt="yes" pets="none">
<SIW:color>RED</SIW:color>
</SIW:herewelive>
</SIW:SIW>
<QDB:QDB>
<QDB:herewelive apt="NO" crackhouse="no">
<QDB:color>Blue</SIW:color>
</QDB:herewelive>
</QDB:QDB>
</ConfigDataFile>

My code is:

xmlDocPtr doc = NULL;
xmlNodePtr node_ptr = NULL;
xmlAttrPtr attr_ptr = NULL;
xmlXPathContextPtr xpathCtx = NULL;
xmlXPathObjectPtr xpathObj = NULL;

xmlInitParser();

doc = xmlParseFile("test.xml");
xpathCtx = xmlXPathNewContext(doc);
xpathObj = xmlXPathEvalExpression("//ConfigDataFile", xpathCtx);
node_ptr = xpathObj->nodesetval->nodeTab[0];

attr_ptr = node_ptr->properties;
while (attr_ptr != NULL)
{
printf("The Node name is %s\n", node_ptr->name);
printf("Attribute name: %s\n",attr_ptr->name);
printf("Attribute value: %s\n",xmlGetProp(node_ptr,
attr_ptr->name));

attr_ptr = attr_ptr->next;

}
return 1;
}

The problem is that when I run this, the output is only:

The Node name is ConfigDataFile
Attribute name: schemaLocation
Attribute value: birdflu.xsd

All the other attributes are not there. I have used my debugger to
look at the entire node, and the other attributes are just not there.
If I change the eval expression to any other node, I can print all the
attributes of that node. The only node that refuses to act how I
desire is the ConfigDataFile node.

Thank you.

 
Reply With Quote
 
 
 
 
Joe Kesselman
Guest
Posts: n/a
 
      06-08-2006
In XPath, namespace nodes are namespace nodes, *not* attribute nodes. If
you want to see them, you need to use the namespace:: axis... which
includes all inherited namespaces as well as those on this specific node.

(XPath 2.0 is changing how it handles namespace information -- long
story -- but the attributes axis will still not include namespace
declarations.)
 
Reply With Quote
 
 
 
 
RichardHatcher.com@gmail.com
Guest
Posts: n/a
 
      06-08-2006
Bless you Mr. Kesselman.

Joe Kesselman wrote:
> In XPath, namespace nodes are namespace nodes, *not* attribute nodes. If
> you want to see them, you need to use the namespace:: axis... which
> includes all inherited namespaces as well as those on this specific node.
>
> (XPath 2.0 is changing how it handles namespace information -- long
> story -- but the attributes axis will still not include namespace
> declarations.)


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do i extract vidios when winrar wont extract them??? help plzzzzzzzz smuttdog@sc.rr.com Computer Support 2 12-23-2007 07:03 AM
while executing my client program i get the exception javax.naming.LinkException: [Root exception is javax.naming.LinkException: [Root exception is javax.naming.NameNotFoundException: remaining if plz anybody know how to solve this problem then mahesh Java 0 03-08-2007 12:26 PM
non root users accessing application installed with root instance hector C Programming 5 12-05-2006 01:01 PM
SRT DIvision, Square root and reciprocal square root alghazo@siu.edu VHDL 0 05-27-2004 06:23 AM
Tertiary Conditional: what does this evaluate to ("docRoot == null ? this.root : doc root")? Rick Osborn Java 10 02-08-2004 02:25 AM



Advertisments