bengmau has asked for the wisdom of the Perl Monks concerning the following question:

What's the easiest way to extract the following data from an xml file to say an array or class object in perl? I just need an example and which xml parse module(s) to use
<valuelist>time|totalTime|serviceLevel|resultString|oidNames[RAW_IN|RA +W_OUT]</valuelist> <unitlist>EpocTime|Seconds|SLAValue|String|RAW|RAW</unitlist> <datalogelement>1107388992|0.00251|1|Default status|2526997135|3422452 +313</datalogelement> <datalogelement>1107389291|0.00224|1|Default status|2535521338|3423007 +889</datalogelement> <datalogelement>1107389591|0.00307|1|Default status|2550911024|3423745 +020</datalogelement> <datalogelement>1107389891|0.00241|1|Default status|2566162886|3424888 +956</datalogelement> <datalogelement>1107390192|0.00236|1|Default status|2584817445|3425778 +169</datalogelement> <datalogelement>1107390492|0.00243|1|Default status|2603853482|3426485 +628</datalogelement> <datalogelement>1107390791|0.00229|1|Default status|2618185706|3427581 +317</datalogelement> <datalogelement>1107391092|0.00235|1|Default status|2632878576|3427950 +009</datalogelement> <datalogelement>1107391392|0.00234|1|Default status|2649691605|3428363 +809</datalogelement> <datalogelement>1107391692|0.00252|1|Default status|2659540151|3428595 +498</datalogelement> <datalogelement>1107391991|0.00235|1|Default status|2666344985|3429129 +946</datalogelement> <datalogelement>1107392292|0.00234|1|Default status|2668397109|3429603 +634</datalogelement>

Replies are listed 'Best First'.
Re: extracting xml info
by borisz (Canon) on Feb 03, 2005 at 20:17 UTC
    perl script.pl data.xml
    use XML::Simple; use Data::Dumper; local $/; my $xs = XML::Simple->new->XMLin('<opt>'.<>.'</opt>'); print Dumper($xs);
    Boris
Re: extracting xml info
by merlyn (Sage) on Feb 03, 2005 at 20:18 UTC
Re: extracting xml info
by dragonchild (Archbishop) on Feb 03, 2005 at 20:15 UTC
    I use XML::Parser, but others really like XML::Simple. Be prepared - XML is a rich datatype and you will have to do some work to get the parser to do exactly what you want it to do.

    Being right, does not endow the right to be rude; politeness costs nothing.
    Being unknowing, is not the same as being stupid.
    Expressing a contrary opinion, whether to the individual or the group, is more often a sign of deeper thought than of cantankerous belligerence.
    Do not mistake your goals as the only goals; your opinion as the only opinion; your confidence as correctness. Saying you know better is not the same as explaining you know better.