SimpleXML & internal entity references
| From: | Rolf Brudeseth | Date: | Sat, 12 Feb 2005 20:33:29 +0000 |
| Subject: | SimpleXML & internal entity references | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-208589@lists.php.net to get a copy of this message | ||
I have spent quite a few hours searching with google, but I am still not sure how to resolve my problem described below:
I am parsing an XML file with SimpleXML (PHP 5.0.3/FreeBSD STABLE-4/i386). It appears that my internal entity references do not get expanded. I see the same behaviour with SAX and PHP5.0.3, while it was not a problem with SAX and PHP4.1.2.
See below, the 'title' gets added to the array, but not the 'price' and 'weight'.
I assume that libxml will expand the entity references? I see the value of 'price' and 'weight' of I look at the data returned by the parser with 'print_r'.
Anybody got an idea where I have gone wrong?
########## XML file ##########
<?xml version='1.0' encoding='iso-8859-1' standalone='yes'?>
<!DOCTYPE prod_desc
[
<!ENTITY dvd '
<price>14.95</price>
<weight>6</weight>
'>
]>
<prod_desc version='1.0'>
<prod item='C107D'>
&dvd;
<title><![CDATA[No more Diapers - DVD]]></title>
</prod>
</prod_desc>
########## PHP code ##########
foreach ($xml->children() as $item)
{
$item_attr = $item->attributes();
foreach ($item->children() as $element => $cdata)
{
// This will not work, bug in PHP
// $prod_array[$item_attr][$element] = $cdata;
// Workaround
$prod_array[eval("return $item_attr;")][eval("return $element;")] = $cdata;
}
}
Rolf
--
Rolf Brudeseth
Software Developer
Personalized Book Shop
rolfb@personalized-books.com
www.personalized-books.com