Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Help parsing XML

by asiufy (Monk)
on Jan 29, 2002 at 01:40 UTC ( #142194=perlquestion: print w/ replies, xml ) Need Help??
asiufy has asked for the wisdom of the Perl Monks concerning the following question:

Monks, I've been very happy with XML::Simple, but now I must learn how to tackle XML where the tag order is relevant:
<test id="1"> <name>Example 1</name> </test> <test id="2"> <name>Example 2</name> </test> <test id="yo"> <name>Example 3</name> </test>
As all of you know, XML::Simple won't return the structure in the exact same way as the original XML structure.

What should I use them? I've looked at a bunch of other XML parsers, and I didn't like any of them.

I'd rather use something tree (non-event) based, as this is how XML::Simple operates, and since I need quick access to the data in the XML tags, I don't want to mess with handlers and stuff like that, unless absolutely necessary, of course.

Any pointers, preferably with meaningful tutorials?

Thanks.

Comment on Help parsing XML
Download Code
Re: Help parsing XML (boo)
by boo_radley (Parson) on Jan 29, 2002 at 01:54 UTC
Re: Help parsing XML
by ferrency (Deacon) on Jan 29, 2002 at 02:24 UTC
    I agree with the XML::Twig suggestion. You can use XML::Twig in tree-mode style or event-mode style. I first started using it tree-mode but quickly realized that event-mode made at least as much sense for my own application.

    If you're using this in a persistant situation, where one perl interpreter will be parsing Many XML documents before dying, be aware that older versions of XML::Twig had a memory leak associated with circular references in internal perl structures. This is fixed in the latest stable version if you have WeakRef installed, and there's a workaround available on the XML::Twig website if you need to use an older version.

    Have fun,
    Alan

Re: Help parsing XML
by krujos (Curate) on Jan 29, 2002 at 04:24 UTC
    As icky as it is XML::DOM provides two really nice parsers. if you need to validate XML::DOM::ValParser is a champ. Both can be even based or tree based. Once you figure it out wading through the structure isnt too bad either. There is a decent review / examples at xml.com good luck
Re: Help parsing XML
by mirod (Canon) on Jan 31, 2002 at 09:40 UTC

    If you need tutorials you can have a look at Kip Hampton's excellent column on XML.com which goes through most of what you can do with Perl and XML. I have a tutorial that gives example with a bunch of XML::Parser based modules, Finally if you want to go the DOM route, there is a new implementation, based on GDOME: XML::GDOME, and I have a helper module in the works, that mostly offers safer navigation: XML::DOM::Twig (it is in alpha mode but the interface should not change, it is just interesting bits of the XML::Twig one layered over the DOM).

Re: Help parsing XML
by Matts (Deacon) on Feb 01, 2002 at 23:30 UTC
    How about XML::XPath? It allows you to go:
    my @test_nodes = $doc->findnodes('//test');
    Of course you have to grok XPath, but for the easy stuff it's just Unix directory paths and a bit more.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (11)
As of 2014-09-18 14:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (116 votes), past polls