I need help with parsing XML. I put an XML doc into a hidden input for an HTML FORM...
<title>TEST TEST</title>
<form method=POST action="http://nflnfl.com/mash.php">
<input type=SUBMIT>
<input type=hidden name=xdoc value='<?xml version="1.0" encoding="UTF-8" ?>
<!--OPN 2001 Proof Of Concept-->
<UploadDate>3/6/2008 3:49:09 PM</UploadDate>

The PHP page includes...


$data = $_POST;
if (!xml_parse($xml_parser, $data, TRUE))
die(sprintf("XML error: %s at line %d column %d",


This works fine on my Windows Vista/Apache 2.2/PHP 5.2.3 server.

But, when I access a LAMP server (PHP 4.3.11) from GoDaddy, I get

XML error: syntax error at line 1 column 14

What am I doing wrong?


Are you sure that the simple xml extension is enabled and that short tags are disabled

Thanks Auzzie!

I have to admit that mere words cannot communicate just how far your comments went over my head ;-}

I used phpinfo() and determined that, indeed, the server where the code worked had short_open_tag OFF, and the server where it failed had it ON.

I tried ...
ini_set("short_open_tag", 0);
...and found the setting didn't work (it was still = 1).

I didn't knowingly exploit the Simple XML Extension.

Can you nudge me towards portable code?


Well i'm guessing that the host has restricted you using ini_set and as for the portable code i unfortunatly will not be able to help you with that as i try to stay away from Simple XML, maybe you could echo the start of the xml declaration?

<input type=hidden name=xdoc value='<?php echo("xml version=\"1.0\" encoding=\"UTF-8\" ?>"); ?>

then carry on as normal afterwards, or if you need to echo the entire xml


Your reply set off the proverbial light bulb above my head...

I stripped off the XML tag from the POST data, and changed the processing to:


xml_parse($xml_parser,"<XML version=\"1.0\" encoding=\"UTF-8\">", FALSE);
xml_parse($xml_parser, $_POST, TRUE);


Now all is well.

Thanks Again,