|
List Info
Thread: Getting dtd and invalid token errors when trying parse file using XML::Parser and XML::XPath
|
|
| Getting dtd and invalid token errors
when trying parse file using XML::Parser
and XML::XPath |

|
2007-10-02 23:15:30 |
|
am getting the following error message
ERROR MESSAGE:
not well-formed (invalid token) at line 1, column 11, byte 11:
XML::Parser=HASH(0x8f83120)
==========^
at /usr/lib/perl5/site_perl/5.8.0/i386-linux-thread-multi/XML/Parser.pm line 187
when I run the below perl script
my $xParserHandle = new XML::Parser(Style => 'Debug');
my $xPathHandle;
$xParserHandle->parsefile($file); $xPathHandle = XML::XPath->new($xParserHandle);
if ( $xPathHandle->exists("//MESSAGE") ) {
getMsgName($xPathHandle);
} else {
getStructName($xPathHandle); }
sub getMsgName {
my $xmlFH = shift; my $args = "//NAME[parent::MESSAGE";
my nodeSet;
my nodes;
nodeSet = $xmlFH->find("$args")->get_nodelist;
nodes = map($_->string_value, nodeSet);
print "MSG NAME: nodesn";
} # END of getMsgName Method
sub getStructName {
my $xmlFH = shift;
my $args = "//NAME[parent::TYPE_DEFINITION"; my nodeSet;
my nodes;
nodeSet = $xmlFH->find("$args")->get_nodelist;
nodes = map($_->string_value, nodeSet);
print "STRUCT NAME: nodesn";
} # END of getStructName Method
Here is my input file
<?xml version="1.0" encoding="iso-8859-1"?> <!DOCTYPE Schema SYSTEM "
schema.dtd">
<FILE DESCRIPTION="Simple"> <TYPE_DEFINITION TYPE="Simple">
<NAME> SimpleTest
</NAME> <DESCRIPTION>
Main Description </DESCRIPTION> <VERSION>
3 </VERSION>
<FIELD> <NAME>
field2 </NAME> <TYPE>
2 </TYPE>
<DESCRIPTION> Field 2 description
</DESCRIPTION> </FIELD> </TYPE_DEFINITION>
</FILE>
Moreover I would like to know how to validate this file against the "schema.dtd" if the dtd exists in a different directory instead of current directory. If I specify dtd in a different directory I get the following error
ERROR MESSAGE:
Failed to open ./schema.dtd:
No such file or directory Handler couldn';t resolve external entity at line 2, column 36, byte 80
error in processing external entity reference at line 2, column 36, byte 80: <?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE Schema SYSTEM "schema.dtd"> ===================================^
<FILE DESCRIPTION="Simple">
at /usr/lib/perl5/site_perl/5.8.0/i386-linux-thread-multi/XML/Parser.pm line 187
I really appreciate your help.
Thanks
Sunil.
|
| Re: Getting dtd and invalid token errors
when trying parse file using XML::Parser
and XML::XPath |

|
2007-10-03 03:33:58 |
On Tue, 2007-10-02 at 21:15 -0700, Sunil wrote:
> am getting the following error message
>
> ERROR MESSAGE:
>
> not well-formed (invalid token) at line 1, column 11,
byte 11:
> XML::Parser=HASH(0x8f83120)
> ==========^
> at
/usr/lib/perl5/site_perl/5.8.0/i386-linux-thread-multi/XML/P
arser.pm line 187
>
>
>
> when I run the below perl script
>
>
>
>
> my $xParserHandle = new XML::Parser(Style =>
'Debug');
> my $xPathHandle;
>
> $xParserHandle->parsefile($file);
> $xPathHandle = XML::XPath->new($xParserHandle);
>
> if ( $xPathHandle->exists("//MESSAGE") )
{
>
> getMsgName($xPathHandle);
>
> } else {
>
> getStructName($xPathHandle);
> }
>
You are passing an XML::Parser object to
XML::XPath->new() which doesn't
work - you must explicitly pass one of filename, xml, ioref
or context.
You probably want to look at the XML::XPath documentation
again but all
you need to do is:
my $xPathHandle = XML::XPath->new(filename =>
$file);
/J
--
This signature kills bloggers
_______________________________________________
Perl-XML mailing list
Perl-XML listserv.ActiveState.com
To unsubscribe: http:/
/listserv.ActiveState.com/mailman/mysubs
|
|
| Re: Getting dtd and invalid token errors
when trying parse file using XML::Parser
and XML::XPath |

|
2007-10-03 11:49:37 |
|
But in cpan, it says you can parse the object of xml parser too to the xpath.
Here is the CPAN XML::XPATH content
Parameters you can use are: filename, parser, xml, ioref and context. The 4 parameters filename, xml, ioref and context are mutually
exclusive - you should only specify one (if you specify anything other
than context, the context node is the root of your document). The
parser option allows you to pass in an already prepared XML::Parser
object, to save you having to create more than one in your application
(if, for example, you're doing more than just XPath).
Since I wanted to validate the xml against DTD and then give it to XPath, I used the option of creating parser object, validate against DTD and pass it to the XPath.
Thanks, Sunil.
On 10/3/07, Jonathan Stowe < jns gellyfish.com">jns gellyfish.com> wrote:
On Tue, 2007-10-02 at 21:15 -0700, Sunil wrote: > am getting the following error message > > ERROR MESSAGE: > > not well-formed (invalid token) at line 1, column 11, byte 11: > XML::Parser=HASH(0x8f83120)
> ==========^ > at /usr/lib/perl5/site_perl/5.8.0/i386-linux-thread-multi/XML/Parser.pm line 187 > > > > when I run the below perl script > > > > > my $xParserHandle = new XML::Parser(Style => 'Debug');
> my $xPathHandle; > > $xParserHandle->parsefile($file); > $xPathHandle = XML::XPath->new($xParserHandle); > > if ( $xPathHandle->exists("//MESSAGE") ) { >
> getMsgName($xPathHandle); > > } else { > > getStructName($xPathHandle); > } >
You are passing an XML::Parser object to XML::XPath->new() which doesn't
work - you must explicitly pass one of filename, xml, ioref or context.
You probably want to look at the XML::XPath documentation again but all you need to do is:
my $xPathHandle = XML::XPath->new(filename => $file);
/J -- This signature kills bloggers _______________________________________________ Perl-XML mailing list Perl-XML listserv.ActiveState.com">Perl-XML listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
|
| Re: Getting dtd and invalid token errors
when trying parse file using XML::Parser
and XML::XPath |

|
2007-10-03 12:27:47 |
On Wed, 2007-10-03 at 09:49 -0700, Sunil wrote:
> But in cpan, it says you can parse the object of xml
parser too to the
> xpath.
>
> Here is the CPAN XML::XPATH content
>
> Parameters you can use are: filename, parser, xml,
ioref and context.
> The 4 parameters filename, xml, ioref and context are
mutually
> exclusive - you should only specify one (if you specify
anything other
> than context, the context node is the root of your
document). The
> parser option allows you to pass in an already prepared
XML::Parser
> object, to save you having to create more than one in
your application
> (if, for example, you're doing more than just XPath).
>
> Since I wanted to validate the xml against DTD and then
give it to
> XPath, I used the option of creating parser object,
validate against
> DTD and pass it to the XPath.
I think you misunderstand what that means. You can pass it a
pre-created
XML::Parser for it to use but you still have to pass one of
filename,
xml, ioref or context. And you still have to use *named
parameters*.
e,g.
$xpath = XML::XPath(parser => $xml_parser, filename
=> $file );
/J
_______________________________________________
Perl-XML mailing list
Perl-XML listserv.ActiveState.com
To unsubscribe: http:/
/listserv.ActiveState.com/mailman/mysubs
|
|
| Re: Getting dtd and invalid token errors
when trying parse file using XML::Parser
and XML::XPath |

|
2007-10-03 14:00:02 |
|
Thanks. I misunderstood. It works now.
Any idea how to set the relative path of DTD document that is specified in the xml. How should I ask parser to look for DTD document in a particular place.
Thanks Sunil.
On 10/3/07, Jonathan Stowe < jns gellyfish.com">jns gellyfish.com> wrote:
On Wed, 2007-10-03 at 09:49 -0700, Sunil wrote: > But in cpan, it says you can parse the object of xml parser too to the > xpath. > > Here is the CPAN XML::XPATH content > > Parameters you can use are: filename, parser, xml, ioref and context.
> The 4 parameters filename, xml, ioref and context are mutually > exclusive - you should only specify one (if you specify anything other > than context, the context node is the root of your document). The
> parser option allows you to pass in an already prepared XML::Parser > object, to save you having to create more than one in your application > (if, for example, you're doing more than just XPath).
> > Since I wanted to validate the xml against DTD and then give it to > XPath, I used the option of creating parser object, validate against > DTD and pass it to the XPath.
I think you misunderstand what that means. You can pass it a pre-created
XML::Parser for it to use but you still have to pass one of filename, xml, ioref or context. And you still have to use *named parameters*.
e,g.
$xpath = XML::XPath(parser => $xml_parser, filename => $file );
/J
_______________________________________________ Perl-XML mailing list Perl-XML listserv.ActiveState.com">Perl-XML listserv.ActiveState.com To unsubscribe:
http://listserv.ActiveState.com/mailman/mysubs
|
[1-5]
|
|