Problem with XML serialization.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jewelthief
Forum Newbie
Posts: 13
Joined: Sat Aug 29, 2009 1:46 am

Problem with XML serialization.

Post 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.
jewelthief
Forum Newbie
Posts: 13
Joined: Sat Aug 29, 2009 1:46 am

Re: Problem with XML serialization.

Post 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();
           
    }
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Re: Problem with XML serialization.

Post 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.
Post Reply