![]() |
XML parsing in Perl
As the world is fast becoming aware of the benifits of XML, perl developers would also want to use XML in their CGI-Perl scripts. XML parsing seems to be one hell of a job when you look at the XML::Parser module, but XML::Simple comes to the rescue with the ease of use it brings.
Installing XML::Simple XML::Simple works by parsing an XML file and returning the data within it as a Perl hash reference. Within this hash, elements from the original XML file play the role of keys, and the CDATA between them takes the role of values. Once XML::Simple has processed an XML file, the content within the XML file can then be retrieved using standard Perl array notation. It can be installed from the shell or CPAN module: Code:
shell> perl -MCPAN -e shellOnce you've got the module installed, create the following XML file and call it "data.xml": Code: XML
Code: Perl
When you run this script, here's what you'll see: Code:
$VAR1 = {Code: Perl
Code:
Pradeep is 23 years old and works in the Programming section |
Re: XML parsing in Perl
hi pradeep,
please provide usage of XML:Sax in an example. |
Re: XML parsing in Perl
i am using this cpan module and this is really useful
But i have a query my xml file looks like this -------------------------------------------- <mac> <calls> <scallPs>83234</scallPs> <sreadPs>7462</sreadPs> <swritPs>7394</swritPs> </calls> <cpu> <usr>10</usr> <sys>3</sys> <wio>0</wio> <idle>87</idle> </cpu> </mac> ------------------------------------------ i can print individual value like $data->{cpu}->{idle} But how can i find no. of elements in <cpu> or <calls> .. which is 3 and 4 respectively. and how can find find the no. of element of <map> which is 2 namely <CPU> and <calls> Thanks in advance |
Re: XML parsing in Perl
I need to parse a huge XML file, please let me know which module to use for the same.
XML file is something like this Code:
<datapoint><name>CMS</name><pid>2416</pid><time>5/10/2010 10:51:50</time><machine>DEWDFTF11382S</machine><CPU>2.48415111588068</CPU><CPUTime>47500</CPUTime><VirtualBytes>338404</VirtualBytes><PrivateBytes>95096</PrivateBytes><HandleCount>2678</HandleCount><Threads>159</Threads> </datapoint> |
Re: XML parsing in Perl
Nice and great suggestion thanks for sharing....
|
| All times are GMT +5.5. The time now is 00:23. |