Hello Peoples!
I am trying to parse an xml file but i keep getting a invalid doc end error! and I cannot figure out what is wrong. Some phantom white space?
it never seems to work..
<?xml version="1.0" ?>
<form>
<global>
<method>POST</method>
<action>forms.php</action>
<table>test_tbl</table>
<description>This is a fun form for you to have fun with</description>
<settings>0,0,0</settings>
<graphic>none</graphic>
<field type="hidden">
<name>test</name>
<value>17</value>
</field>
</global>
</form>
<?php
$parser = xml_parser_create();
function startElement($parser, $elm, $attr) {
echo $elm;
}
function endElement($parser, $elm) {
echo $elm;
}
function charData($parser, $leaf) {
echo $leaf;
}
xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
xml_set_element_handler($parser, "startElement", "endElement");
xml_set_character_data_handler($parser, "charData");
$file = "forms.xml";
if (!file_exists($file)) {
print "Error loading XML file - please check the file exists and that you have access to it.";
exit;
} else {
print "XML file loaded successfully!<BR /><BR />";
}
if (!xml_parse($parser, $data, true)) {
print "<H2>Unrecoverable XML error encountered! </H2>";
printf("<P> The error report was '%s at line %d'</P>",
xml_error_string(xml_get_error_code($parser)),
xml_get_current_line_number($parser));
} else {
print "<BR /><BR />Parsing complete.";
}
xml_parser_free($parser);
?>
I run it and I end up with:
XML file loaded successfully!
Unrecoverable XML error encountered!
The error report was 'Invalid document end at line 1' 😕
I dont know whats wrong with my .xml file it shows up fine in my firefox browser!! No symantic errors or anything. Any ideas?? 😕
Thanks for your insight!