472,950 Members | 2,042 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,950 software developers and data experts.

Please help extract attributes from root node.

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" xmlns:xsi="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.

Jun 8 '06 #1
2 1714
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.)
Jun 8 '06 #2
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.)


Jun 8 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Alex | last post by:
It seems that XML Serializatoin automatically puts certain XSD attributs in the root node. How can I control the root node attributes emitted to something more custom so I can preserve my schema...
2
by: Maersa | last post by:
hi, i'm trying to add "attributes" to some nodes and it works at design time but fails at runtime. XmlDocument doc = new XmlDocument(); XmlElement elem = doc.CreateElement( "root" );...
1
by: Chua Wen Ching | last post by:
Hi there, I have some problems when reading XML file. 1. First this, is what i did, cause i can't seem to read "sub elements or tags" values, so i place those values into attributes like this....
3
by: Steven | last post by:
Following is the string ... <ADDRESSINFO name = "Cedar Ave" no = "21123" attrib ="visible"> <HOUSE name ="main" type ="1" value ="2200"/> <HOUSE name ="slide" type ="12" value ="123"/> <HOUSE...
2
by: Sebastian Araya | last post by:
Hello, I'm trying to create a single function to append new nodes to a DOMDocument object: public function addElement( $element, $name, $value = '', $attrs = Null ) { if( !( $created =...
1
by: David Van D | last post by:
Hi there, A few weeks until I begin my journey towards a degree in Computer Science at Canterbury University in New Zealand, Anyway the course tutors are going to be teaching us JAVA wth bluej...
6
by: Jakub.Bednarczuk | last post by:
Hallo everybody I have the problem with getting attributes values and also attributes names. I am reading an xml file with DOM. Lets see an example: file I read <root> <Def></Def>...
2
by: rds80 | last post by:
In the xml document below, I would like to retrieve the distinct attributes for the element '<Bal>'. However, I haven't had any success. Here is what I have so far: <TRANS> <TRAN...
12
by: blackirish | last post by:
Hi all, I am trying to merge 2 XML files that first of all i need to compare nodes of both files according to 2 attributes in the nodes. If those 3 attributes are equal, i need to replace the...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.