You are here: SimpleXML & internal entity references « PHP « IT news, forums, messages
SimpleXML & internal entity references

Posted by Rolf Brudeseth on 02/12/05 22:33

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

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация