Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: XML::Simple XML / XMLin / XMLout? or something else?

by tobyink (Abbot)
on Oct 12, 2012 at 13:43 UTC ( #998680=note: print w/ replies, xml ) Need Help??


in reply to XML::Simple XML / XMLin / XMLout? or something else?

XML::Simple is almost certainly not what you want to be using. Here's an example using XML::LibXML...

use XML::LibXML 1.70; my $xml = XML::LibXML->load_xml(IO => \*DATA); foreach my $book ($xml->getElementsByTagName('book')) { print "GOT THIS: " . $book->toString . "\n"; } __DATA__ <booklist> <book> <author>Book 1 author 1</author> <author>Book 1 author 2</author> <title>Book 1 title</title> <isbn>Book1ISBN</isbn> </book> <book> <author>Book 2 author 1</author> <author>Book 2 author 2</author> <title>Book 2 title</title> <isbn>Book2ISBN</isbn> </book> <book> <author>Book 3 author 1</author> <author>Book 3 author 2</author> <author>Book 3 author 3</author> <title>Book 3 title</title> <isbn>Book3ISBN</isbn> </book> </booklist>
perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'


Comment on Re: XML::Simple XML / XMLin / XMLout? or something else?
Download Code
Replies are listed 'Best First'.
Re^2: XML::Simple XML / XMLin / XMLout? or something else?
by choroba (Canon) on Oct 12, 2012 at 13:49 UTC
    Or, using the XML::XSH2 wrapper of XML::LibXML:
    open 1.xml ; for /booklist/book ls . ;
    لսႽ ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

      Wow. That makes it simple! Thanks

Re^2: XML::Simple XML / XMLin / XMLout? or something else?
by Roboz (Novice) on Oct 12, 2012 at 14:19 UTC

    This looks like a good method to me! I plan on spitting out each <book></book> to SOAP::Lite to pass to a web service and, of course, it expects each XML chunk to have the original format... Naturally the XML I'm dealing with is much more complex but this gets me where I want to go. Thanks.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (10)
As of 2015-07-29 08:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (261 votes), past polls