XML::Parser examples for the novice
XML::Parser examples for the novice
am 15.11.2005 12:31:50 von lars
What are some good examples or explanations of using XML::Parser?
The man pages don't give me quite enough to get started with and I'm
looking for something to bridge the gap at or closer to the novice level.
the examples and explanations in the man pages are too abbreviated and take
short cuts which (for me) obscure how they are to be used in a different
context.
Specifically, I'd like to strip out processing statments and a few other
elements.
--
Lars
Software patents harm all Net-based business, write your MEP:
http://wwwdb.europarl.eu.int/ep6/owa/p_meps2.repartition?ilg =EN
Re: XML::Parser examples for the novice
am 15.11.2005 13:22:07 von John Bokma
lars@nospam.nosoftwarepatents.edu wrote:
> What are some good examples or explanations of using XML::Parser?
>
> The man pages don't give me quite enough to get started with and I'm
> looking for something to bridge the gap at or closer to the novice
> level. the examples and explanations in the man pages are too
> abbreviated and take short cuts which (for me) obscure how they are to
> be used in a different context.
>
> Specifically, I'd like to strip out processing statments and a few
> other elements.
However, you might want to look at some of the other XML modules.
--
John Small Perl scripts: http://johnbokma.com/perl/
Perl programmer available: http://castleamber.com/
I ploink googlegroups.com :-)
Re: XML::Parser examples for the novice
am 15.11.2005 20:28:47 von lars
John Bokma wrote:
:
: However, you might want to look at some of the other XML modules.
Thanks. That's a step, but I'm still wondering how to weed out processing
statements and comments (well that part I get) while accumulating the
everything else into a buffer unmodified. I'll try some more variations.
Maybe it's just something obvious.
My first thought *was* to use another parser. XML::TokeParser seems easier,
but since this will be a plug-in for a larger program which already uses
XML::Parser, I'd like to avoid using another module if there's away to do
it with XML::parser
--
Lars
Software patents harm all Net-based business, write your MEP:
http://wwwdb.europarl.eu.int/ep6/owa/p_meps2.repartition?ilg =EN
Re: XML::Parser examples for the novice
am 16.11.2005 00:36:29 von John Bokma
lars@nospam.nosoftwarepatents.edu wrote:
> John Bokma wrote:
> :
>
> : However, you might want to look at some of the other XML modules.
>
> Thanks. That's a step, but I'm still wondering how to weed out
> processing statements and comments (well that part I get) while
> accumulating the everything else into a buffer unmodified. I'll try
> some more variations. Maybe it's just something obvious.
>
> My first thought *was* to use another parser. XML::TokeParser seems
> easier, but since this will be a plug-in for a larger program which
> already uses XML::Parser, I'd like to avoid using another module if
> there's away to do it with XML::parser
XML::Parser is a dinosaur. It's fast, but normally you don't want to use
it directly unless you want to :-). Most wrappers are way more friendly.
I am sure that there are modules that do what you want in just a few
lines. The whole idea of modules is that you use as much as possible, if
that makes your work better :-).
Have a look at XML::Twig:
http://xmltwig.com/xmltwig/twig_stable.html#METHODS_XML_Twig _new_pi
"pi
Set the way processing instructions are processed: 'drop', 'keep'
(default) or 'process'"
"comments
Set the way comments are processed: 'drop' (default), 'keep' or
'process'"
If you insist on XML::Parser:
use strict;
use warnings;
use XML::Parser;
my $parser = new XML::Parser(
Style => 'Stream',
Handlers => {
Comment => \&xml_comment,
Proc => \&xml_pi
},
);
$parser->parse( <<'XML' );
some text
XML
sub xml_comment {
return;
}
sub xml_pi {
return;
}
--
John Small Perl scripts: http://johnbokma.com/perl/
Perl programmer available: http://castleamber.com/
I ploink googlegroups.com :-)
Re: XML::Parser examples for the novice
am 16.11.2005 09:27:20 von Bart Lateur
lars@nospam.nosoftwarepatents.edu wrote:
>My first thought *was* to use another parser. XML::TokeParser seems easier,
>but since this will be a plug-in for a larger program which already uses
>XML::Parser, I'd like to avoid using another module if there's away to do
>it with XML::parser
I think XML::TokeParser is a layer on top of XML::Parser. So
technically, you're still using the same parser... ;-)
--
Bart.