Page 1 of 1

Problem with XML serialization.

Posted: Mon Jan 18, 2010 12:26 pm
by jewelthief
Here is my code.

Code: Select all

<?php 
    session_start();
    ini_set("include_path", ini_get('include_path').PATH_SEPARATOR.'./PEAR/'.PATH_SEPARATOR.'./PEAR/PEAR/' );
    if( !isset( $_GET["sess"] ) )
    {
        $xmlstring = file_get_contents("php://input");   
        $xml = new DOMDocument();
        $xml->loadXML($xmlstring);
        $_SESSION["xmlData"] = $xmlstring;
    }
    else
    {
           require_once("Serializer.php");
           echo $_SESSION["xmlData"];
           $sr = new XML_Serializer();
           $sr->serialize($xml);
           echo $sr->getSerializedData();
           
    }
    
?>
I am storing xml document in session variable and want to access it on next page in the form of string. I found out PEAR packages so tried it. Now in my line of code, when i call getSerializedData(), I see 'undefined' when alert() xmlHttpResponse.responseText.

Does anyone has any idea where am i going wrong? Any help would be appriciated.

Re: Problem with XML serialization.

Posted: Mon Jan 18, 2010 12:37 pm
by jewelthief
Sorry I pasted the wrong code in previous post. Here is the one i am actually using.

Code: Select all

session_start();
    ini_set("include_path", ini_get('include_path').PATH_SEPARATOR.'./PEAR/'.PATH_SEPARATOR.'./PEAR/PEAR/' );
    if( !isset( $_GET["sess"] ) )
    {
        $xmlstring = file_get_contents("php://input");   
        $xml = new DOMDocument();
        $xml->loadXML($xmlstring);
        $_SESSION["xmlData"] = $xml;
    }
    else
    {
           require_once("Serializer.php");
           $xml = $_SESSION["xmlData"];
           $sr = new XML_Serializer();
           $sr->serialize($xml);
           header('Content-type: text/xml'); 
           echo $sr->getSerializedData();
           
    }

Re: Problem with XML serialization.

Posted: Mon Jan 18, 2010 6:51 pm
by Weirdan
You cannot reliably deserialize DomDocument (http://us2.php.net/serialize#function.serialize.notes , http://bugs.php.net/bug.php?id=30323). Store $xmlstring instead.