Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Jun 2002
    Posts
    101
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Issue using PEAR::XML_Unserializer

    When parsing XML into an array using XML_Unserializer it fails when encountering the & character. It turns out that XML_Unserializer are using xml_parse when parsing the xml. Does anyone know how to solve this problem?

    A small script to demonstrate the issue:
    <?PHP
    require('XML/Unserializer.php');

    $XML_unserializer = &new XML_Unserializer();

    $xml = '<?xml version="1.0" encoding="iso-8859-1" ?>
    <product>
    <id>573</id>
    <name>Clean Dishwash - Shiny result</name>
    <description>
    A highly concentrated modern dishwasher powder for the best results.
    Low dosages for reduced environmental impact, and thereby also inexpensive and economical in use.
    Breaks down grime and fat in a gentle manner and without damaging d&eacute;cor and also keeps your dishwasher gleaming.
    The bottle comes with a childproof cap. Enough for up to 50 wash loads. Weight: 750 g
    </description>
    <price_ex_vat>5.61</price_ex_vat>
    <vat>1.35</vat><category>Cleaning products</category>
    </product>';

    //Unserialize the XML data structure
    $products = $XML_unserializer->unserialize($xml);

    //Check whether unserialization of XML worked
    if(PEAR::isError($products)){
    die($products->getMessage());
    }

    //Get unserialized data
    $feed = $XML_unserializer->getUnserializedData();

    echo "<pre>";
    print_r($feed);
    echo "</pre>";
    ?>
    Last edited by Pompiuses; 09-29-2004 at 01:48 PM.

  • #2
    Regular Coder
    Join Date
    Jun 2002
    Posts
    905
    Thanks
    23
    Thanked 5 Times in 5 Posts
    I'm not 'up-to-date' with XML however if the problem is that the PHP code errors when it see's the & sign.. why not just escape that sign using \&.

    Looking at the code you provided to try and give you an example using your code, I cannot actually find the & in there at all. Furthermore, have you tried using the ASCII code for this instead of the actual &? thats provided you are printed the & to a page as I can't see the & in your code I cannot decied which you are doing.

    Any use?

  • #3
    Regular Coder
    Join Date
    Jun 2002
    Posts
    101
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by sir pannels
    I'm not 'up-to-date' with XML however if the problem is that the PHP code errors when it see's the & sign.. why not just escape that sign using \&.

    Looking at the code you provided to try and give you an example using your code, I cannot actually find the & in there at all. Furthermore, have you tried using the ASCII code for this instead of the actual &? thats provided you are printed the & to a page as I can't see the & in your code I cannot decied which you are doing.

    Any use?
    I solved it by just setting & to &amp;

  • #4
    Regular Coder
    Join Date
    Jun 2002
    Posts
    905
    Thanks
    23
    Thanked 5 Times in 5 Posts
    so using the ascii.. good work


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •