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

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -