...

View Full Version : Issue using PEAR::XML_Unserializer



Pompiuses
09-29-2004, 02:43 PM
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>";
?>

sir pannels
10-01-2004, 01:48 PM
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?

Pompiuses
10-01-2004, 01:58 PM
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; :D

sir pannels
10-01-2004, 11:45 PM
so using the ascii.. good work :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum