in reply to Example of XML::Parse object style requested

Okay, first of all:
$ perldoc XML::Parser

Second of all,

XML::Simple
will accomplish this for you and it will do so much easier. So:
$ perldoc XML::Simple
And a quick synopsis:
#!/usr/bin/perl use XML::Simple; use strict; # use strict, always use strict $x = new XML::Simple(); $xref = $x->XMLin('/path/to/xmlfile'); # $xref now stores your xml in a hashref

I strongly suggest you read the docs above though because there are a few attribute options for the <text>XML::Simple</text> object that you will want to at least know about.




Amel

Replies are listed 'Best First'.
Re: Re: Example of XML::Parse object style requested
by mirod (Canon) on Apr 17, 2002 at 21:30 UTC

    You might want to ask a little bit more about the problem before recommending XML::Simple. XML::Simple works great for data-oriented XML, but as soon as you have to deal with documents, that usually include mixed content (<p>this is <b>mixed</b> content</p>: text and sub-elements mixed within an element) then you just can't use it. The content field of the hash can only hold one text, not several as is the case with mixed content.

    Plus what if the data to be processed is 4Gb of XML log?

    That said there are no tutorials that I am aware of on the Object style of XML::Parser.

    Plus XML::Parser is not really the favored way to process XML any more (read it is not actively maintained and its interface is not standard): XML::libXML, or XML::XPath, or (shameless plug!) XML::Twig are good alternatives. Plus of course XML::Simple if your XML is nice enough to fit in it ;--)

Re: Re: XML::Parser
by yangtse (Acolyte) on May 03, 2002 at 16:00 UTC
    Thank you. XML::Simple is good enough for my project.