I'm a Perl newbie. I have the following in myfile.xml
<detail> <start> <nonterminal name="A" /> </start> <rules> <rule name="A" type="text"> <nonterminal name="AA" /> <nonterminal name="AC" /> <nonterminal name="AD" /> <nonterminal name="AB" /> <nonterminal name="AE" /> </rule> <rule name="AA" type="numeric"> <token>1</token> <token>10</token> </rule> <rule name="AC" type="alpanumeric"> <token>3</token> <nonterminal name="BE" /> <nonterminal name="CE" /> <token>30</token> </rule> <rule name="CE" type="special"> <token>var1</token> <token>var2</token> </rule> <rule name="BE" type="symbol"> <token>%</token> <token>#</token> </rule> </rules> </detail>
My program to read the above:
use XML::Simple; use Data::Dumper; my $file_name = "myfile.xml"; my $xmlObj = XML::Simple->new(); my $data = $xmlObj->XMLin($file_name); my $primitive = 'A' foreach my $mydata(keys %{$data->{rules}{rule}{$primitive}{nontermin +al}}) { print $mydata; print " "; }
The output I got is
AC
AA
AE
AB
AD
but I wanted it in its original position, ie,
AA
AC
AD
AB
AE
and how would I print a mix of nonterminal and token (as in rule AC)?
Please help.
In reply to XML::Simple How to print data in its original position by Z_S
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |