You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-dev@xerces.apache.org by Fran Orzel <fm...@us.ibm.com> on 2009/08/12 22:51:37 UTC
Question on DOM Traversal
Given an XML file that looks as follows:
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<vpdc date="Feb 18 2009" time="17:07:11" version="1.0">
<some_data info1="E12" info2="MNXK4" info3="1997" >
<other_data>this is the data</other_data>
<other_data1> some other data </other_data1>
</some_data>
<some_records>
<record1 data1="CAGE" data2="LION" data3="DEFAULT">
<time_of_day>20090205144231</time_of_day>
</record1>
<record2 data1="BOX" data2="ADOG" data3="45454545">
<time_of_day>20090205144231</time_of_day>
</record2>
<recordn data1="BOWL" data2="ACAT" data3="31313131">
<time_of_day>20090205144231</time_of_day>
</recordn>
</records>
</vpdc>
I want to parse this file and put save the data into linked lists such
that I have an entry for each major record (<vpdc>, <system>, <record1>,
<record2> and <recordn>). For each of these I want to have a linked list
for the "data" associated with each record. For example:
LList1 =
<vpdc> with pointer to linked list of data for date, time and
version
<some_data> with pointer to linked list of data for info1, info2, info3,
other_data and other_data1
<record1> with pointer to linked list of data for data1, data2, data3 and
time_of_day
<record2> with pointer to linked list of data for data1, data2, data3 and
time_of_day
<record3> with pointer to linked list of data for data1, data2, data3 and
time_of_day
The problem I am having is that I do not know how many other_data and
time_of_day possible entries there may be. I have looked at the
DOMCount.cpp sample and wanted to so something similar to this since in
the future I may have even more "subtrees" of data then I do now.......
When I implemented a version of the DOMCOunt code tyring to get the
non-attribute data for the nodes, I get a TEXT_NODE for each of the
records with no value attached to it, so I can't use the existence of a
text-node to clearly indicate that I have some data I want to keep (since
I want to ignore those values). I also tried a TreeWalker but that would
mean recognizing that I have to go down additional subtrees and I may not
know how many of them I have....
Any hints, samples, ideas ?????
Thanks,
Fran