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
user name
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=&quot;1.0&quot; encoding=&quot;iso-8859-1"?>
<!DOCTYPE Schema SYSTEM " schema.dtd&quot;>
 &nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; 
<FILE DESCRIPTION="Simple"&gt;
 &nbsp;  <TYPE_DEFINITION TYPE=";Simple&quot;>
 &nbsp; &nbsp; &nbsp;  <NAME&gt;
 &nbsp; &nbsp; &nbsp; &nbsp;   ;  SimpleTest
 &nbsp; &nbsp; &nbsp;  </NAME&gt;
 &nbsp; &nbsp; &nbsp;  <DESCRIPTION>
 &nbsp; &nbsp;   ; &nbsp; &nbsp; Main Description
 &nbsp; &nbsp; &nbsp;  </DESCRIPTION>
 &nbsp; &nbsp; &nbsp;  <VERSION>
 &nbsp; &nbsp; &nbsp; &nbsp;   ; 3
 &nbsp; &nbsp; &nbsp;  </VERSION>
 &nbsp; &nbsp; &nbsp;  <FIELD&gt;
 &nbsp; &nbsp; &nbsp; &nbsp;   ; <NAME&gt;
 &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;   ; field2
 &nbsp; &nbsp; &nbsp; &nbsp;   ; </NAME&gt;
 &nbsp; &nbsp; &nbsp; &nbsp;   ; <TYPE&gt;
 &nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; 2
 &nbsp; &nbsp; &nbsp; &nbsp;   ; </TYPE&gt;
 &nbsp; &nbsp; &nbsp; &nbsp;   ; <DESCRIPTION>
 &nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; Field 2 description
 &nbsp; &nbsp;   ; &nbsp; &nbsp; </DESCRIPTION>
 &nbsp; &nbsp; &nbsp;  </FIELD>
 &nbsp; </TYPE_DEFINITION&gt;
</FILE&gt;


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=&quot;1.0&quot; encoding=&quot;iso-8859-1"?>
<!DOCTYPE Schema SYSTEM "schema.dtd";>
===================================^
 
<FILE DESCRIPTION="Simple"&gt;
 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.
 &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp; 
 &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;


Re: Getting dtd and invalid token errors when trying parse file using XML::Parser and XML::XPath
user name
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-XMLlistserv.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
user name
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 < jnsgellyfish.com">jnsgellyfish.com> wrote:
On Tue, 2007-10-02 at 21:15 -0700, Sunil wrote:
>; am getting the following error message
&gt;
> ERROR MESSAGE:
&gt;
> not well-formed (invalid token) at line 1, column 11, byte 11:
> XML::Parser=HASH(0x8f83120)
&gt; ==========^
; at /usr/lib/perl5/site_perl/5.8.0/i386-linux-thread-multi/XML/Parser.pm line 187
>
&gt;
>
&gt; when I run the below perl script
>;
>
>
>
> my $xParserHandle = new XML::Parser(Style => 'Debug');
&gt; my $xPathHandle;
>
&gt; $xParserHandle->parsefile($file);
> $xPathHandle = XML::XPath->new($xParserHandle);
>
&gt; if ( $xPathHandle->exists("//MESSAGE&quot;) ) {
>
&gt; &nbsp; &nbsp;   ; &nbsp; getMsgName($xPathHandle);
>
> } else {
>
>; &nbsp; &nbsp; &nbsp; &nbsp; 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:

 ; &nbsp; &nbsp; &nbsp; my $xPathHandle = XML::XPath->new(filename => $file);

/J
--
This signature kills bloggers
_______________________________________________
Perl-XML mailing list
Perl-XMLlistserv.ActiveState.com">Perl-XMLlistserv.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
user name
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-XMLlistserv.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
user name
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 < jnsgellyfish.com">jnsgellyfish.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
&gt;
> Parameters you can use are: filename, parser, xml, ioref and context.
> The 4 parameters filename, xml, ioref and context are mutually
&gt; 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
&gt; 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.

&nbsp; $xpath = XML::XPath(parser => $xml_parser, filename => $file );


/J


_______________________________________________
Perl-XML mailing list
Perl-XMLlistserv.ActiveState.com">Perl-XMLlistserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

[1-5]

about | contact  Other archives ( Real Estate discussion Medical topics )