XML::Parser Style => Object

Ask a Question related to PERL Modules, Design and Development.

  1. #1

    Default XML::Parser Style => Object

    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 Guest

  2. Similar Questions and Discussions

    1. Object Style Options
      When pasting a selection of different graphics frames with different formating from one document to another. Sometimes the frames change there...
    2. .net recieving null object while accessing axis message style web service
      Hi, Recieving null object when message style web service isaccessed from vb.net client. SOAP messages are fine. My webservice uses the method...
    3. Need help with Style conversion from Style object to Style key/value collection.
      I am writing a custom control that derives from the DataGrid control. I would like to apply SelectedItemStyles and ItemStyles for use in my derived...
    4. HTML-Parser / SGML-Parser
      Ok, silly question. I am writing a script to determine my router's WAN ip address and then to email me once an hour in case it changes. Currently...
    5. Number format German style => English style when importing CSV files into MySQL-DB
      Hi there, I'm trying to import a csv file into my MySQL database. Unfortunately the number format for the price column is formatted in German...
  3. #2

    Default Re: XML::Parser Style => Object

    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 (
    > [url]http://perl-xml.sourceforge.net/faq/[/url] once again ;--) for more information.
    >
    > --
    > Michel Rodriguez
    > Perl &amp; XML
    > [url]http://www.xmltwig.com[/url]
    Mark J Fenbers Guest

  4. #3

    Default Re: XML::Parser Style => Object

    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 (
    [url]http://perl-xml.sourceforge.net/faq/[/url] once again ;--) for more information.

    --
    Michel Rodriguez
    Perl &amp; XML
    [url]http://www.xmltwig.com[/url]

    Michel Rodriguez Guest

  5. #4

    Default Re: XML::Parser Style => Object

    In comp.lang.perl.misc Michel Rodriguez <mirod@xmltwig.com> 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

    thumb_42@yahoo.com Guest

  6. #5

    Default Re: XML::Parser Style => Object


    Michel Rodriguez <mirod@xmltwig.com> 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. ] [email]ben@morrow.me.uk[/email]
    Ben Morrow Guest

  7. #6

    Default Re: XML::Parser Style => Object

    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 Guest

  8. #7

    Default Re: XML::Parser Style => Object

    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
    [url]http://www.xmltwig.com[/url]

    Michel Rodriguez Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139