Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

XML::Parser Issues

by shug94 (Sexton)
on Aug 06, 2009 at 01:39 UTC ( [id://786278]=perlquestion: print w/replies, xml ) Need Help??

shug94 has asked for the wisdom of the Perl Monks concerning the following question:

I am attempting to use the XML::Parser module to parse an xml file. I am running ActiveState's ActivePerl on a windows box, and I am running the script from an Apache Tomcat Server.

I get the following error whenever I try to parse the xml:
Error: “Aug 5, 2009 4:53:55 PM org.apache.catalina.core.ApplicationCon +text log INFO: cgi: runCGI (stderr):no element found at line 1, column 0, byte +-1 at C:/Perl/lib/XML/Parser.pm line 187”


The fact that it tries to access byte '-1' is concerning. Line 187 of Parser.pm looks like this, so I think it might be a problem with the expat package?
187: $result=$expat->parse($arg);

I have verified my xml at the following web address: http://www.w3schools.com/Dom/dom_validate.asp

I have also removed my more complex xml and replaced it with simple xml and it still doesn’t work.

What can I do to fix this problem? I am struggling to find help on the web. The general consensus with this problem (according to google) seems to be that the xml files are invalid or reference unavailable external files. With my code this is not the case.

The code I use for opening and (attempting) to parse the file:
use XML::Parser; $filterXSDFilename = 'data/ppp-sbg-types.xsd'; if(open(FILTER_XSD_FILE, $filterXSDFilename)) { print "Content-type: text/html\n\n"; @xsdFileContentsArray = <FILTER_XSD_FILE>; print "The array is: " . @xsdFileContentsArray; print "File Length in lines: " . $xsdFileContentsArray; $xsdFileContentsAsScalar = concatenateXSDFileContents(@xsdFileConten +tsArray); my $parser = new XML::Parser(Handlers => { Start => \&handleStartTag, End => \&handleEndTag, Char => \&handleCharacterStrings, Default => \&handleDefault,}); $parser->parse($xsdFileContentsArray); print ("A RetrieveEventHistoryRequest has been generated.<P><P>"); } else { print "Content-type: text/html\n\n"; print ("A RetrieveEventHistoryRequest has not been generated.<P><P>" +); print ("<HR><P><P>"); print ("There was an error loading the following xsd file: " . $filt +erXSDFilename . "<BR>"); } #Params are an array of the lines of the xsd file. sub concatenateXSDFileContents (@) { @lines = @_; $lineSize = @lines; print $lineSize; print "<BR>\n"; $index = 0; $returnString = ""; while($index < $lineSize) { $returnString .= $lines[$index]; $index++; } return $returnString; } sub handleStartTag($$%) { my ($expat, $element, %attributeList) = @_; print "StartTag - Element Name: $element"; } sub handleEndTag() { } sub handleCharacterStrings() { } sub handleDefault() { }

If any of you can point me in the right direction, then I would appreciate it greatly,

Thanks in advance,
Cameron

Replies are listed 'Best First'.
Re: XML::Parser Issues
by shug94 (Sexton) on Aug 06, 2009 at 02:36 UTC
    I have figured it out for myself.
    I decided to try using 'use strict', and subsequently found that I was passing the wrong variable into my call to the parser.
    I should have been passing the $xsdFileContentsAsScalar variable rather than the $xsdFileContentsArray.
    I just got confused. Sorry for wasting your time.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://786278]
Approved by jettero
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (7)
As of 2024-04-19 17:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found