Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Parsing XML with XML::Simple

by brian_d_foy (Abbot)
on Dec 18, 2006 at 00:53 UTC ( #590365=note: print w/ replies, xml ) Need Help??


in reply to Parsing XML with XML::Simple

This seems to work for me. You mentioned wrapping a root element around it, but did you include the <?xml ...?> bit? Even when I remove that, though, it still works. Does it fail with your sample file?

#!/usr/bin/perl use XML::Simple; my $xml = do { local $/; <DATA> }; my $hash = XMLin( $xml ); use Data::Dumper; print Dumper( $hash ); __END__ <?xml version="1.0"?> <root> <CVS> $Id: File_Find.pl,v 1.1 2006-12-17 19:25:03 eric Exp $ </CVS> <DATE>2006-12-10</DATE> <INTRODUCTION>Blah</INTRODUCTION> <TITLE>Foo</TITLE> <AUTHOR>Bar</AUTHOR> <ARTICLE> foo bar baz </ARTICLE> </root>

It looks like the hash does what it should:

]$ perl test $VAR1 = { 'INTRODUCTION' => 'Blah', 'CVS' => ' $Id: File_Find.pl,v 1.1 2006-12-17 19:25:03 eric Exp $ ', 'ARTICLE' => ' foo bar baz ', 'TITLE' => 'Foo', 'AUTHOR' => 'Bar', 'DATE' => '2006-12-10' };

Update: If I move the data out to a file and use XMLin( $ARGV[0], NoAttr => 1 ) it still works.

--
brian d foy <brian@stonehenge.com>
Subscribe to The Perl Review


Comment on Re: Parsing XML with XML::Simple
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (9)
As of 2014-07-12 21:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (241 votes), past polls