tfeitor has asked for the wisdom of the Perl Monks concerning the following question:
Like I said before I'm new with perl :) 4 hours, I need to parse a lot of files in a Production Env, I tried the code bellow:<?xml version="1.0"?> <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envel +ope/"> <soapenv:Body> <dlwmin:getBookById xmlns:dlwmin="http://www.test.com/integration" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <result xmlns="http://www.test.com/integration/integration"> <status> <state>0</state> </status> <books> <num>12345</num> <book> <code_a>11111</code_a> <name>Come to the Dark Side 1st Ed</name> <otherVal>ABC</otherVal> <otherVal2>1999</otherVal2> </book> <book> <code_a>22222</code_a> <name>Come to the Dark Side 2nd Ed</name> <otherVal>ABC</otherVal> <otherVal2>2001</otherVal2> </book> <Title>Come to the Dark Side</Title> <typeOfBook>SciFi</typeOfBook> <writer>Darth Vader</writer> </books> </result> </dlwmin:getBookById> </soapenv:Body> </soapenv:Envelope>
and this one (I couldn't understand how to interate with the hash):use strict; use warnings; use XML::LibXML; use XML::LibXML qw( ); my $parser = XML::LibXML->new(); my $doc = $parser->parse_file('out.xml'); for my $result ($doc->findnodes('/books/book')) { for my $interv ($result->findnodes('book')) { my $bk = $interv->find('code_a'); my $bk_name = $interv->find('name'); print("$bk - $bk_name"); } }
antoher thing the xml was in one line. thanksuse strict; use XML::Simple; use Data::Dumper; my $doc = XMLin('out.xml'); print Dumper($doc);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: XML Parse
by choroba (Cardinal) on Jun 02, 2015 at 17:23 UTC | |
|
Re: XML Parse
by jellisii2 (Hermit) on Jun 03, 2015 at 11:39 UTC | |
|
Re: XML Parse
by Anonymous Monk on Jun 02, 2015 at 17:14 UTC | |
|
Re: XML Parse
by thargas (Deacon) on Jun 04, 2015 at 11:09 UTC | |
|
Re: XML Parse
by Anonymous Monk on Jun 02, 2015 at 21:48 UTC |