SimpleXML & internal entity references

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxxxxxxxxxxxxx
www.personalized-books.com


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux