If i use your script like this:
$xml = '<?xml version="1.0"?>
<response>
<ticketID>1197027955_8310</ticketID>
<status>OK</status>
<errCode>200</errCode>
<errMsg></errMsg>
</response>';
$obj = new DOMDocument();
$obj->loadXML( $xml );
echo print_r( $obj, true );
echo $obj->saveXML() . PHP_EOL;
The first statement writes:
DOMDocument Object
(
)
The second:
<?xml version="1.0"?>
<response>
<ticketID>1197027955_8310</ticketID>
<status>OK</status>
<errCode>200</errCode>
<errMsg/>
</response>
It's just the xml is not properly stored in loadXML method... but the
string must be inside due to saveXML returns the proper value.
Nathan Nobbe escribió:
On Dec 10, 2007 12:08 PM, Dani Castaños <danitao.mailists@xxxxxxxxx
<mailto:danitao.mailists@xxxxxxxxx>> wrote:
Yep, it works when i do saveXML, but not on loadXML step...
did the loadXML() method work in the test script i sent over in my
last post?
if it does then something else is going on when loadXML() is called in
the context
of your application.
The thing is... i'm trying to do something like this:
$request = $_POST['xml'];
$logger->debug( 'New ticket request' );
/**
* Parse XML request to obtain values
*/
$xml = new DOMDocument();
//$xml->validateOnParse = true;
$xml->loadXML( $request );
you should always sanitize input. at the very least you should be
running $_POST['xml']
through a call to trim() before handing it to the DOMDocument instance.
$request = trim($_POST['xml']);
$xml = new DOMDocument();
$xml->loadXML($request);
i suspect there is some garbage in or around the string contained in
$_POST['xml'] that
the DomDocument instance doesnt like, therefore its not behaving the
way youd anticipate.
for example if you modify the script i sent over last time by putting
some spaces in between the
xml declaration and the opening tag of the envelope (<response>) you
should see the following error
(or something similar [depending on the value of error_reporting])
Warning: DOMDocument::loadXML(): XML declaration allowed only at the
start of the document in Entity,
line: 3 in /home/nathan/testDom.php on line 19
which consequently leads to
<?xml version="1.0"?>
when invoking
echo $domDoc->saveXML() . PHP_EOL;
rather than
<?xml version=" 1.0"?>
<response>
<ticketID>1197026188_ec76</ticketID>
<status>KO</status>
<errCode>500</errCode>
<errMsg>Internal Server Error</errMsg>
</response>
which is what you would expect.
-nathan
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php