XML::Simple in perl, with mixed xml file -
i have demo.xml file this.
<?xml version="1.0"?> <data> <pattern>123456</pattern> <pattern>654321</pattern> <pattern>abcdefg</pattern> <pattern owners="alex">heloworld</pattern> <pattern owners="alex">perlprogramming</pattern> </data>
this perl code parse file:
use xml::simple; use strict; use data::dumper; $xml = new xml::simple; $data = $xml->xmlin("demo.xml"); print dumper($data);
and here got:
$var1 = { 'pattern' => [ '123456', '654321', 'abcdefg', { 'owners' => 'alex', 'content' => 'heloworld' }, { 'owners' => 'alex', 'content' => 'perlprogramming' } ] };
may know if print out content of xml tag, should ?
the expected output might like:
123456 654321 acdefg heloworld perlprogramming
thank much!
alex
rule 1 of using xml::simple
: don't, use else.
i xml::twig
, problem looks this:
#!/usr/bin/perl use strict; use warnings; use xml::twig; $twig = xml::twig -> new -> parsefile('demo.xml'); foreach $pattern ( $twig -> get_xpath ('//pattern') ) { print $pattern -> text,"\n"; }
Comments
Post a Comment