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
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.