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

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:,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:,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 <>
Subscribe to The Perl Review

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (7)
As of 2021-03-01 17:13 GMT
Find Nodes?
    Voting Booth?
    My favorite kind of desktop background is:

    Results (15 votes). Check out past polls.