RE: :Parser errors
by John Cope other posts by this author
Jul 26 2000 4:19AM messages near this date
view in the new Beta List Site
Re: XML::Parser errors
|
Re: RFC: XML::ValidWriter
Sabrina,
> -----Original Message-----
> From: perl-xml-admin@[...].com [mailto:perl-xml-
admin@[...].com]On Behalf Of Sabrina Ahmed
> Sent: Tuesday, July 25, 2000 11:23 AM
> To: perl-xml@[...].com
> Subject: XML::Parser errors
>
>
> Hi all,
Hi, back again eh. Weren't sastified with the last responses? Neither was I!
>
> I am trying to create simple perl files to parse my xml documents and am
using
> XML::Parser. However, in the scripts i have written, i keep getting the
same error so
> i am wondering if i am doing something fundamentally wrong. My scripts are
just to
> parse an xml file and give the info as html. i am doing a web-based
project to
> describe information about images and basically want the perl script to
parse the xml
> document and show the relevent information in a web environment. However,
even my test
> scripts aren't working. the error i get is:
>
> Global symbol "$p1" requires explicit package name at ./xmltest.pl line 6.
> Execution of ./xmltest.pl aborted due to compilation errors.
That's Perl telling you there's an error in the compilation phase of
execution. You should be familiar with "use strict" (and all it's
trappings - declare vars with my) and always run your scripts with warnings
enabled (-w). To get help with strictly Perl related questions, ask in an
appropriate forum like Perl-for-Win32 hosted by ActiveState (they'll accept
questions even if you're on an OS foreign to Win32, it's all Perl to them)
or usenet's news:comp.lang.perl.misc.
>
> I have looked at perldoc XML::Parser to try and get more information but
to no avail.
> Is there fundamentally something I am missing and do i have to specify the
actual file
> to parse or will the parser recognise the files with an .xml extension.
Hope you can
> help,
>
There was some advice last time you asked that you look into XSLT. There's
two modules I know that process xsl (stylesheets); XML-XSLT and Sablotron.
To try to get you up to speed quickly, try this (requires XML-XSLT):
#!perl -w
use strict;
use XML::XSLT;
my $xml =<<EOXML;
<?xml version='1.0'?>
<doc>
<item>
One
</item>
<item>
Two
</item>
</doc>
EOXML
my $xsl =<<EOXSL;
<?xml version='1.0'?>
<xsl:stylesheet
xmlns:xsl='http://www.w3.org/1999/XSL/Transform'
xmlns='http://www.w3.org/TR/REC-html40'>
<xsl:template>
<xsl:apply-templates />
</xsl:template>
<xsl:template match='/'>
<html xmlns='http://www.w3.org/1999/xhtml' lang='en' xml:lang='en'>
<ul>
<xsl:apply-templates match="item" />
</ul>
</html>
</xsl:template>
<xsl:template match="item">
<li>
<xsl:value-of select='.' />
</li>
</xsl:template>
</xsl:stylesheet>
EOXSL
my $htmlfile = 'xsl-transformation.html';
my $obj = XML::XSLT-> new($xsl, 'STRING');
$obj-> transform_document($xml, 'STRING');
$obj-> print_result($htmlfile);
__END__
Don't sweat the little bits of stuff you don't understand here, just try it,
modify it, read the module docs and have some fun.
John G. Cope
Thread:
Sabrina Ahmed
Ian Boreham
John Cope
|