473,804 Members | 3,744 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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" ?>
<ConfigDataFi le xmlns:SRI="SRI" xmlns:SIW="SIW" xmlns:QBQ="QBQ"
xmlns:VLD="VLD" xmlns:xsi="http ://www.mstsc.com/schema"
xsi:schemaLocat ion="birdflu.xs d">
<SIW:SIW>
<SIW:hereweli ve apt="yes" pets="none">
<SIW:color>RE D</SIW:color>
</SIW:herewelive>
</SIW:SIW>
<QDB:QDB>
<QDB:hereweli ve 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;
xmlXPathContext Ptr xpathCtx = NULL;
xmlXPathObjectP tr xpathObj = NULL;

xmlInitParser() ;

doc = xmlParseFile("t est.xml");
xpathCtx = xmlXPathNewCont ext(doc);
xpathObj = xmlXPathEvalExp ression("//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("Attribu te name: %s\n",attr_ptr->name);
printf("Attribu te value: %s\n",xmlGetPro p(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 1771
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
2211
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 link?
2
9309
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" ); elem.InnerXml = "<first>abcde</first><last>1234</last>";
1
3446
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. Before: ----------
3
2663
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 name ="major" type ="1" value ="1234"/> <HOUSE name ="branch" type ="1" value ="31980"/> </ADDRESSINFO> <ADDRESSINFO name = "5th Street" no = "65653" attrib ="visible">
2
4264
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 = $this->createElement( $name, $value ) ) )
1
9663
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 and I was wondering if anyone here would be able to give me some tips for young players such as myself, for learning the language. Is this the best Newsgroup for support with JAVA?
6
1902
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> <Elements> <Element att1="1" att2="2" att3="3" //Some attributes are
2
4320
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 TRAN_DESC_CD="ACRT" TRAN_DESC="Actual Rate">
12
18326
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 existing node with the new one. For example first xml file will be like; <Root> <Node Id ="1" FormId="form1" Value="value1"/> <Node Id ="2" FormId="form1" Value="value2"/> <Node Id ="3" FormId="form1" Value="value3"/>...
0
9706
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10569
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10315
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10075
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9140
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6847
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5519
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4295
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2990
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.