List Info

Thread: parsing xml file using xmlTextReader




parsing xml file using xmlTextReader
user name
2006-07-19 17:23:46
If you are more interested in creating the output than
learning to code
with libxml2, you may want to use xslt to convert your input
XML
document into your desired output.
Xsltproc is one of executables you can use for such
transformations:
http://xmlsoft.
org/XSLT/xsltproc.html

> -----Original Message-----
> From: David Kinyanjui [mailto:david_kinyanjuiyahoo.com]
> Sent: Monday, July 17, 2006 7:01 PM
> To: xmlgnome.org
> Subject: [xml] parsing xml file using xmlTextReader
> 
> Hello everyone;
> I'm trying to extract data from a xml file and use it
> for a report... I
> have just come across xmlTextReader.
> I'm hoping to parse/extract the values/counts for
> (date, currdollar,
> gender) and load it into a map.
> I'm thinking the key for the map can be the dates'
> value/count then the
> value for the map can be the a structure of two vector
> (one contain the
> currdollar and another for gender).
> In other words, the data will need to be grouped by
> date and currdollar
> as you may notice on the sample output.
> Then I can use this map to display the data in
> different forms.
> 
> Thanks in advance your asssitance.
> 
> The following is an xml and output samples:
> 
> <?xml version="1.0"
encoding="utf-8" ?>
> <dps:services xmlns:dps="uri">
> <dps:output>
> 
> <dps:tally dps:name="test_1">
>   <dps:tally dps:name="date">
>     <dps:tally dps:name="currdollar">
>       <dps:tally dps:name="Gender">
>         <dps:value>U</dps:value>
>         <dps:count>4</dps:count>
>       </dps:tally>
>       <dps:tally dps:name="Gender">
>         <dps:value>M</dps:value>
>         <dps:count>57</dps:count>
>       </dps:tally>
>       <dps:tally dps:name="Gender">
>         <dps:value>I</dps:value>
>         <dps:count>5</dps:count>
>       </dps:tally>
>       <dps:tally dps:name="Gender">
>         <dps:value>F</dps:value>
>         <dps:count>220</dps:count>
>       </dps:tally>
>       <dps:tally dps:name="Gender">
>         <dps:value>C</dps:value>
>         <dps:count>1</dps:count>
>       </dps:tally>
>       <dps:tally dps:name="Gender">
>         <dps:value>A</dps:value>
>         <dps:count>18</dps:count>
>       </dps:tally>
>       <dps:value>000-005</dps:value>
>       <dps:count>305</dps:count>
>     </dps:tally>
>     <dps:tally dps:name="currdollar">
>       <dps:tally dps:name="Gender">
>         <dps:value>U</dps:value>
>         <dps:count>18</dps:count>
>       </dps:tally>
>       <dps:tally dps:name="Gender">
>         <dps:value>M</dps:value>
>         <dps:count>82</dps:count>
>       </dps:tally>
>       <dps:tally dps:name="Gender">
>         <dps:value>I</dps:value>
>         <dps:count>14</dps:count>
>       </dps:tally>
>       <dps:tally dps:name="Gender">
>         <dps:value>F</dps:value>
>         <dps:count>330</dps:count>
>       </dps:tally>
>       <dps:tally dps:name="Gender">
>         <dps:value>C</dps:value>
>         <dps:count>1</dps:count>
>       </dps:tally>
>       <dps:tally dps:name="Gender">
>         <dps:value>A</dps:value>
>         <dps:count>33</dps:count>
>       </dps:tally>
> 
> 
>       <dps:value>005-010</dps:value>
>       <dps:count>478</dps:count>
>     </dps:tally>
>     <dps:tally dps:name="currdollar">
>       <dps:tally dps:name="Gender">
>         <dps:value>U</dps:value>
>         <dps:count>20</dps:count>
>       </dps:tally>
>       <dps:tally dps:name="Gender">
>         <dps:value>M</dps:value>
>         <dps:count>109</dps:count>
>       </dps:tally>
>       <dps:tally dps:name="Gender">
>         <dps:value>I</dps:value>
>         <dps:count>25</dps:count>
>       </dps:tally>
>       <dps:tally dps:name="Gender">
>         <dps:value>F</dps:value>
>         <dps:count>490</dps:count>
>       </dps:tally>
>       <dps:tally dps:name="Gender">
>         <dps:value>C</dps:value>
>         <dps:count>6</dps:count>
>       </dps:tally>
>       <dps:tally dps:name="Gender">
>         <dps:value>B</dps:value>
>         <dps:count>1</dps:count>
>       </dps:tally>
>       <dps:tally dps:name="Gender">
>         <dps:value>A</dps:value>
>         <dps:count>56</dps:count>
>       </dps:tally>
>       <dps:value>010-015</dps:value>
>       <dps:count>707</dps:count>
>     </dps:tally>
>     <dps:tally dps:name="currdollar">
>       <dps:tally dps:name="Gender">
>         <dps:value>U</dps:value>
>         <dps:count>8</dps:count>
>       </dps:tally>
>       <dps:tally dps:name="Gender">
>         <dps:value>M</dps:value>
>         <dps:count>34</dps:count>
>       </dps:tally>
>       <dps:tally dps:name="Gender">
>         <dps:value>I</dps:value>
>         <dps:count>3</dps:count>
>       </dps:tally>
>       <dps:tally dps:name="Gender">
>         <dps:value>F</dps:value>
>         <dps:count>160</dps:count>
>       </dps:tally>
>       <dps:tally dps:name="Gender">
>         <dps:value>C</dps:value>
>         <dps:count>1</dps:count>
>       </dps:tally>
>       <dps:tally dps:name="Gender">
>         <dps:value>A</dps:value>
> 
> 
> 
>         <dps:count>13</dps:count>
>       </dps:tally>
>       <dps:value>015-020</dps:value>
>       <dps:count>219</dps:count>
>     </dps:tally>
>     <dps:tally dps:name="currdollar">
>       <dps:tally dps:name="Gender">
>         <dps:value>U</dps:value>
>         <dps:count>30</dps:count>
>       </dps:tally>
>       <dps:tally dps:name="Gender">
>         <dps:value>M</dps:value>
>         <dps:count>131</dps:count>
>       </dps:tally>
>       <dps:tally dps:name="Gender">
>         <dps:value>I</dps:value>
>         <dps:count>17</dps:count>
>       </dps:tally>
>       <dps:tally dps:name="Gender">
>         <dps:value>F</dps:value>
>         <dps:count>683</dps:count>
>       </dps:tally>
>       <dps:tally dps:name="Gender">
>         <dps:value>C</dps:value>
>         <dps:count>6</dps:count>
>       </dps:tally>
>       <dps:tally dps:name="Gender">
>         <dps:value>A</dps:value>
>         <dps:count>74</dps:count>
>       </dps:tally>
>       <dps:value>020-025</dps:value>
>       <dps:count>941</dps:count>
>     </dps:tally>
>     <dps:tally dps:name="currdollar">
>       <dps:tally dps:name="Gender">
>         <dps:value>U</dps:value>
>         <dps:count>12</dps:count>
>       </dps:tally>
>       <dps:tally dps:name="Gender">
>         <dps:value>M</dps:value>
>         <dps:count>84</dps:count>
>       </dps:tally>
>       <dps:tally dps:name="Gender">
>         <dps:value>I</dps:value>
>         <dps:count>5</dps:count>
>       </dps:tally>
>       <dps:tally dps:name="Gender">
>         <dps:value>F</dps:value>
>         <dps:count>251</dps:count>
>       </dps:tally>
>       <dps:tally dps:name="Gender">
>         <dps:value>C</dps:value>
>         <dps:count>4</dps:count>
>       </dps:tally>
>       <dps:tally dps:name="Gender">
>         <dps:value>B</dps:value>
>         <dps:count>1</dps:count>
>       </dps:tally>
>       <dps:tally
> dps:name="Gender">
> 
> 
> 
>         <dps:value>A</dps:value>
>         <dps:count>20</dps:count>
>       </dps:tally>
>       <dps:tally dps:name="Gender">
>         <dps:value>7</dps:value>
>         <dps:count>1</dps:count>
>       </dps:tally>
>       <dps:value>025-050</dps:value>
>       <dps:count>378</dps:count>
>     </dps:tally>
>     <dps:tally dps:name="currdollar">
>       <dps:tally dps:name="Gender">
>         <dps:value>U</dps:value>
>         <dps:count>2</dps:count>
>       </dps:tally>
>       <dps:tally dps:name="Gender">
>         <dps:value>M</dps:value>
>         <dps:count>18</dps:count>
>       </dps:tally>
>       <dps:tally dps:name="Gender">
>         <dps:value>I</dps:value>
>         <dps:count>1</dps:count>
>       </dps:tally>
>       <dps:tally dps:name="Gender">
>         <dps:value>F</dps:value>
>         <dps:count>59</dps:count>
>       </dps:tally>
>       <dps:tally dps:name="Gender">
>         <dps:value>A</dps:value>
>         <dps:count>9</dps:count>
>       </dps:tally>
>       <dps:value>050-075</dps:value>
>       <dps:count>89</dps:count>
>     </dps:tally>
>     <dps:tally dps:name="currdollar">
>       <dps:tally dps:name="Gender">
>         <dps:value>F</dps:value>
>         <dps:count>5</dps:count>
>       </dps:tally>
>       <dps:value>075-100</dps:value>
>       <dps:count>5</dps:count>
>     </dps:tally>
>     <dps:value>200602</dps:value>
>     <dps:count>3122</dps:count>
>   </dps:tally>
>   <dps:tally dps:name="date">
>     <dps:tally dps:name="currdollar">
>       <dps:tally dps:name="Gender">
>         <dps:value>U</dps:value>
>         <dps:count>6</dps:count>
>       </dps:tally>
>       <dps:tally dps:name="Gender">
>         <dps:value>M</dps:value>
>         <dps:count>37</dps:count>
>       </dps:tally>
>       <dps:tally dps:name="Gender">
>         <dps:value>I</dps:value>
>         <dps:count>4</dps:count>
>       </dps:tally>
>       .
> 
> 
> 
> .
>       .
>       .
>   </dps:tally>
> </dps:tally>
> 
> </dps:output>
> </dps:services>
> 
> output sample:
> 200602,3122,000-005,305,U,4
> 200602,3122,000-005,305,M,57
> 200602,3122,000-005,305,I,5
> 200602,3122,000-005,305,F,220
> 200602,3122,000-005,305,C,1
> 200602,3122,000-005,305,A,18
> 200602,3122,005-010,478,U,18
> 200602,3122,005-010,478,M,82
> 200602,3122,005-010,478,I,14
> 200602,3122,005-010,478,F,330
> 200602,3122,005-010,478,C,1
> 200602,3122,005-010,478,A,33
> 200602,3122,010-015,707,U,20
> 200602,3122,010-015,707,M,109
> 200602,3122,010-015,707,I,25
> 200602,3122,010-015,707,F,490
> 200602,3122,010-015,707,C,6
> 200602,3122,010-015,707,B,1
> 200602,3122,010-015,707,A,56
> 200602,3122,015-020,219,U,8
> 200602,3122,015-020,219,M,34
> 200602,3122,015-020,219,I,3
> 200602,3122,015-020,219,F,160
> 200602,3122,015-020,219,C,1
> 200602,3122,015-020,219,A,13
> 200602,3122,020-025,941,U,30
> 200602,3122,020-025,941,M,131
> 200602,3122,020-025,941,I,17
> 200602,3122,020-025,941,F,683
> 200602,3122,020-025,941,C,6
> 200602,3122,020-025,941,A,74
> .
> .
> .
> 200602,3122,075-100,26,U,1
> 200602,3122,075-100,26,M,7
> 200602,3122,075-100,26,I,2
> 200602,3122,075-100,26,F,11
> 200602,3122,075-100,26,A,5
> 
> __________________________________________________
> Do You Yahoo!?
> Tired of spam?  Yahoo! Mail has the best spam
protection around
> http://mail.yahoo.com

_______________________________________________
xml mailing list, project page  http://xmlsoft.org/
xmlgnome.org
http://mai
l.gnome.org/mailman/listinfo/xml
parsing xml file using xmlTextReader
user name
2006-07-19 17:54:26
ABeylinaxsone.com wrote:
> If you are more interested in creating the output than
learning to code
> with libxml2, you may want to use xslt to convert your
input XML
> document into your desired output.
> Xsltproc is one of executables you can use for such
transformations:
> http://xmlsoft.
org/XSLT/xsltproc.html
> 
> 

That is an excellent suggestion. There is a good XSLT
tutorial on line at:
http://www.zvon.org/xxl/XSLTutorial/Output/index.html

(There are also XML and XPATH tutorials there.)

A great site that has a detailed XSLT FAQ is here:
http://www.dpawson.co.u
k/xsl/

Once you understand the basics, you should join the mailing
list that 
you can find here:
h
ttp://www.mulberrytech.com/xsl/xsl-list/index.html

and post your question there, or search the archives to see
if an answer 
exists. A bunch of real XSLT hotshots (the person who wrote
Saxon, for 
instance) read the list and are endlessly patient in
answering questions 
and helping people. Of course, after you understand the
basics of XSLT, 
you might not need any help to solve your problem. Either
way, after 
that you just need to develop your XSL stylesheet and use it
with xsltproc.

I know it doesn't necessarily sound easy, but it's
probably easier than 
writing a C or C++ program to do what you want.

- Rush
_______________________________________________
xml mailing list, project page  http://xmlsoft.org/
xmlgnome.org
http://mai
l.gnome.org/mailman/listinfo/xml
[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )