Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > XML::Parser Style => Object

Reply
Thread Tools

XML::Parser Style => Object

 
 
Mark J Fenbers
Guest
Posts: n/a
 
      02-14-2004
Does anyone have some sample code I could examine to learn how to use the
XML:arser package when Style is set to Objects? E.g.,

my $p = new XML:arser(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>

 
Reply With Quote
 
 
 
 
Mark J Fenbers
Guest
Posts: n/a
 
      02-14-2004
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:arser 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:arser?
> XML:arser 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


 
Reply With Quote
 
 
 
 
Michel Rodriguez
Guest
Posts: n/a
 
      02-14-2004
Mark J Fenbers wrote:
> Does anyone have some sample code I could examine to learn how to use the
> XML:arser 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:arser?
XML:arser 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

 
Reply With Quote
 
thumb_42@yahoo.com
Guest
Posts: n/a
 
      02-15-2004
In comp.lang.perl.misc Michel Rodriguez <(E-Mail Removed)> wrote:

> Is there any specific reason why you chose to use XML:arser?
> XML:arser 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:arser (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:arser I've ever been
mixed up with was dealing with name spaces.

I've done some pretty wild stuff with XML:arser, 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

 
Reply With Quote
 
Ben Morrow
Guest
Posts: n/a
 
      02-15-2004

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


I was under the impression that XML:arser 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. ] http://www.velocityreviews.com/forums/(E-Mail Removed)
 
Reply With Quote
 
Bart Lateur
Guest
Posts: n/a
 
      02-15-2004
Ben Morrow wrote:

>I was under the impression that XML:arser 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.
 
Reply With Quote
 
Michel Rodriguez
Guest
Posts: n/a
 
      02-16-2004
Bart Lateur wrote:

>>I was under the impression that XML:arser 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:arser 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:arser if you can believe it).

XML:arser 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:OM (although I would not
recommend using XML:OM, but rather XML::LibXML), XML:YX...

In the last 2/3 years the perl XML community has largely shifted from
XML:arser (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:arser 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:arser 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:urePerl does not need to be
compiled and can work in such an environment too).

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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how do I get the style sheets (or style object) of the wholedocument? Jake Barnes Javascript 6 04-12-2009 08:15 AM
Object creation - Do we really need to create a parent for a derieved object - can't the base object just point to an already created base object jon wayne C++ 9 09-22-2005 02:06 AM
All style tags after the first 30 style tags on an HTML page are not applied in Internet Explorer Rob Nicholson ASP .Net 3 05-28-2005 03:11 PM
Copying the style object from one object to another Sparhawk Javascript 5 08-29-2004 09:50 AM
Need help with Style conversion from Style object to Style key/value collection. Ken Varn ASP .Net Building Controls 0 04-26-2004 07:06 PM



Advertisments