Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: XML::Simple Not getting the proper output. ( xml2XMLRules

by Anonymous Monk
on Jun 13, 2014 at 06:28 UTC ( #1089769=note: print w/replies, xml ) Need Help??


in reply to XML::Simple Not getting the proper output.

See your problem is you're using XML::Simple, switch to XML::Rules and your problem will go away :) Re^3: Parsing XML (XML::Rules xml2XMLRules )
#!/usr/bin/perl -- #~ xml-simple-to-xml-rules-1089765.pl #~ 2014-06-12-23:31:16 by Anonymous Monk #~ #~ #~ perltidy -csc -otr -opr -ce -nibc -i=4 #!/usr/bin/perl -- use strict; use warnings; use XML::Rules; use XML::Simple qw/ XMLin /; use Data::Dump qw/ dd /; my $shortxmlraw = q{<?xml version='1.0'?> <employees> <employee> <name>John Doe</name> <age>43</age> <sex>M</sex> <department>Operations</department> </employee> <employee> <name>Jane Doe</name> <age>31</age> <sex>F</sex> <department>Accounts</department> </employee> </employees>}; my $xmlin = XML::Rules->new( qw/ stripspaces 8 /, rules => ## the result of xml2XMLRules foo.xml foo2.xml .... { 'age,department,name,sex' => 'content', 'employee' => 'as array no content', 'employees' => 'no content' }, ); dd({ YES => $xmlin->parse( $shortxmlraw ) }); dd({ NO => XMLin( $shortxmlraw ) }); __END__ { YES => { employees => { employee => [ { age => 43, department => "Operations", name => "John +Doe", sex => "M" }, { age => 31, department => "Accounts", name => "Jane Do +e", sex => "F" }, ], }, }, } { NO => { employee => { "Jane Doe" => { age => 31, department => "Accounts", sex = +> "F" }, "John Doe" => { age => 43, department => "Operations", sex + => "M" }, }, }, }

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1089769]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (3)
As of 2021-01-24 00:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?