Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Strip that XML!

by ruzam (Curate)
on Feb 20, 2009 at 21:11 UTC ( [id://745447]=note: print w/replies, xml ) Need Help??


in reply to Strip that XML!

Not an answer, but in all the answer examples given the XML source is not proper XML (at least for this purpose). Sure there are 'email' tags and there are 'name' tags but there's no 'email/name' container gluing the two together. At best you can only guarantee that the sample can be parsed into an array of emails and an array of names, but making assumptions that there is an association between the email and name is eventually going to bite you.

Here's a 'functionally' equivalent source sample:
my $_='<xml> <email>toto@foo.com</email> <email>tata@bar.com</email> <email>tutu@baz.com</email> <name>Toto</name> <name>Tata</name> <name>Tutu</name> </xml>';
And so is this:
my $_='<xml> <email>tata@bar.com</email> <email>toto@foo.com</email> <name>Tutu</name> <email>tutu@baz.com</email> <name>Toto</name> <name>Tata</name> </xml>';

The examples above are both valid representations of the original source sample and I'm pretty sure XML parsers are within their design rights to re-organize the data as they see fit.

A better source for example answer code would be this:
my $_='<xml> <user><email>toto@foo.com</email><name>Toto</name></user> <user><email>tata@bar.com</email><name>Tata</name></user> <user><email>tutu@baz.com</email><name>Tutu</name></user> </xml>';

Originally posted as a Categorized Answer.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (7)
As of 2024-04-16 08:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found