From: "Avraham Shapiro" <[EMAIL PROTECTED]>
> I'm crossposting this to Perl and XML listservs since it involves XML parsing 
>  from within Perl.
> 
> I'm having trouble parsing a simple bit of XML with XML::XQL::DOM.

Why would anyone want to use DOM to work with XML? I doubt there is 
any more wordy and longwinded way to handle XML.

It's hard to know what do you actually want to do with your XML, but 
it seems you are trying to store the different <msg>s into a hash 
using the class as the key, probably to use that later. 

You might like the XML::Rules way where for each tag you specify what 
data are you interested in or the code you want to execute for the 
tag, its attributes, content and the data extracted from the subtags.

Eg in this case you might do something like

# http://search.cpan.org/~jenda/XML-Rules-1.03/lib/XML/Rules.pm
my $parser = XML::Rules->new(
  rules => {
    msg => 'by class',
    onFalseMsg => 'no content',
    test => sub {
      my ($tag, $attr) = @_;
      print qq{Test: $attr->{id} type})
Short message: $attr->{onFalseMsg}{short}
Long message: $attr->{onFalseMsg}{long}
};
      return;
    },
  }
);

$parser->parse($the_xml);

With the additional advantage that you do not keep the whole XML 
parsed into a maze of objects in memory, but instead as soon as you 
are done parsing and processing the <test> tag you can forget its 
contents.

HTH, Jenda
===== [EMAIL PROTECTED] === http://Jenda.Krynicky.cz =====
When it comes to wine, women and song, wizards are allowed 
to get drunk and croon as much as they like.
        -- Terry Pratchett in Sourcery

_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to