XML::Parser Style => Object

Discussion in 'Perl Misc' started by Mark J Fenbers, Feb 14, 2004.

  1. Does anyone have some sample code I could examine to learn how to use the
    XML::parser package when Style is set to Objects? E.g.,

    my $p = new XML::parser(Style => Objects");
    $p-Parsefile("myfile.xml");
    # now what?

    I'm still pretty green at Perl, and maybe "now what?" is obvious to more
    experienced Perl coders, but not me...

    Here is an excerpt of "myfile.xml" which I'd like to be able to parse and make
    use of the data somehow in my Perl code...

    <?xml version="1.0 ?>
    <site id="ZLPP1">
    <sigstages>
    <action>8.0</action>
    <flood>11.0</flood>
    <moderate>13.0</moderate>
    <major>17.0</major>
    <record>19.4</record>
    </sigstages>
    <observed>
    <datum>
    <stage units="feet">3.16</stage>
    <valid timezone="EST">2004/02/14 02:15</valid>
    </datum>
    <datum>
    <stage units="feet">3.10</stage>
    <valid timezone="EST">2004/02/14 02:45</valid>
    </datum>
    </observed>
    </site>
    Mark J Fenbers, Feb 14, 2004
    #1
    1. Advertising

  2. Yes, XML::Simple works great for me! Thanks for the tip!
    Mark

    Michel Rodriguez wrote:

    > Mark J Fenbers wrote:
    > > Does anyone have some sample code I could examine to learn how to use the
    > > XML::parser package when Style is set to Objects? E.g.,
    > > [...]
    > > I'm still pretty green at Perl, and maybe "now what?" is obvious to more
    > > experienced Perl coders, but not me...
    > > [...]

    >
    > Is there any specific reason why you chose to use XML::parser?
    > XML::parser is really a low level module, that IMHO should not be used
    > directly.
    >
    > I think XML::Simple would work just fine in your case. It will read the
    > XML into a Perl data structure. Or try XML::LibXML, or XML::Twig if you
    > need more features. Look at the FAQ (
    > http://perl-xml.sourceforge.net/faq/ once again ;--) for more information.
    >
    > --
    > Michel Rodriguez
    > Perl &amp; XML
    > http://www.xmltwig.com
    Mark J Fenbers, Feb 14, 2004
    #2
    1. Advertising

  3. Mark J Fenbers wrote:
    > Does anyone have some sample code I could examine to learn how to use the
    > XML::parser package when Style is set to Objects? E.g.,
    > [...]
    > I'm still pretty green at Perl, and maybe "now what?" is obvious to more
    > experienced Perl coders, but not me...
    > [...]


    Is there any specific reason why you chose to use XML::parser?
    XML::parser is really a low level module, that IMHO should not be used
    directly.

    I think XML::Simple would work just fine in your case. It will read the
    XML into a Perl data structure. Or try XML::LibXML, or XML::Twig if you
    need more features. Look at the FAQ (
    http://perl-xml.sourceforge.net/faq/ once again ;--) for more information.

    --
    Michel Rodriguez
    Perl &amp; XML
    http://www.xmltwig.com
    Michel Rodriguez, Feb 14, 2004
    #3
  4. Mark J Fenbers

    Guest

    In comp.lang.perl.misc Michel Rodriguez <> wrote:

    > Is there any specific reason why you chose to use XML::parser?
    > XML::parser is really a low level module, that IMHO should not be used
    > directly.


    Of the XML solutions out there that I've seen, (mostly java ones) I still
    find XML::parser (in event mode) the easiest/fastest. (I haven't messed with
    that many perl modules for XML though)

    Takes a little bit to get used to at first, since the documentation
    introduces it as some sort of tree that is rather difficult to grok, but if
    you skip passed that and get to the event model, it's easy to process XML.
    (seems pretty fast too). Only difficult thing of XML::parser I've ever been
    mixed up with was dealing with name spaces.

    I've done some pretty wild stuff with XML::parser, and can say that it's
    enjoyable. :)

    I'd almost rather build my own custom tree than to deal with any DOM level
    stuff. (unless I were writing XML)

    Jamie
    , Feb 15, 2004
    #4
  5. Mark J Fenbers

    Ben Morrow Guest

    Michel Rodriguez <> wrote:
    > Is there any specific reason why you chose to use XML::parser?
    > XML::parser is really a low level module, that IMHO should not be used
    > directly.


    I was under the impression that XML::parser was more-or-less
    deprecated now, in favour of SAX... is that not correct?

    Ben

    --
    Heracles: Vulture! Here's a titbit for you / A few dried molecules of the gall
    From the liver of a friend of yours. / Excuse the arrow but I have no spoon.
    (Ted Hughes, [ Heracles shoots Vulture with arrow. Vulture bursts into ]
    /Alcestis/) [ flame, and falls out of sight. ]
    Ben Morrow, Feb 15, 2004
    #5
  6. Mark J Fenbers

    Bart Lateur Guest

    Ben Morrow wrote:

    >I was under the impression that XML::parser was more-or-less
    >deprecated now, in favour of SAX... is that not correct?


    That was what Matt Sergeant, maintainer of most of the XML modules,
    seems to be wanting, yes. I'm not sure I agree.

    --
    Bart.
    Bart Lateur, Feb 15, 2004
    #6
  7. Bart Lateur wrote:

    >>I was under the impression that XML::parser was more-or-less
    >>deprecated now, in favour of SAX... is that not correct?

    >
    > That was what Matt Sergeant, maintainer of most of the XML modules,
    > seems to be wanting, yes. I'm not sure I agree.


    I think XML::parser should be deprecated for "regular users". It is not
    actively supported any more, and if you want to learn a streaming
    interface, you might as well learn SAX (although SAX is lower-level than
    XML::parser if you can believe it).

    XML::parser is still useful as a basic XML parsing layer for other
    modules though, that give a higher-level API: XML::Simple (can also work
    on top of a SAX parser), XML::Twig, XML::DOM (although I would not
    recommend using XML::DOM, but rather XML::LibXML), XML::pYX...

    In the last 2/3 years the perl XML community has largely shifted from
    XML::parser (and expat), to XML::LibXML (based on libxml2), which is a
    lot more powerful, giving you XML parsing but also DOM, XPath,
    XInclude... The only problems with XML::LibXML is that as the library
    and the module are both still work in progress, they have sometimes
    stability issues, you have to find the proper combination of
    libxml2/XML::LibXML that works and stick to it for a while
    (<pet_peeve>and that said, XML::parser has had its problems too: the
    interface to the DTD events for example has changed quite a few times in
    incompatible ways</pet_peeve> ;--)

    A plus of XML::parser is also that it comes installed with Activestate
    Perl, which might make it easier for people who don't have a compiler on
    their system (but note that XML::SAX::purePerl does not need to be
    compiled and can work in such an environment too).

    --
    Michel Rodriguez
    Perl &amp; XML
    http://www.xmltwig.com
    Michel Rodriguez, Feb 16, 2004
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ken Varn
    Replies:
    0
    Views:
    439
    Ken Varn
    Apr 26, 2004
  2. arne
    Replies:
    0
    Views:
    351
  3. Erik Wasser
    Replies:
    5
    Views:
    445
    Peter J. Holzer
    Mar 5, 2006
  4. Sean
    Replies:
    3
    Views:
    267
    robic0
    Oct 3, 2006
  5. Sean
    Replies:
    0
    Views:
    365
Loading...

Share This Page