Problem with "undefined entities" using DOM

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

I have a problem with both DOM and SimpleXML. I'm reading an XML file
which has a DOCTYPE declaration using a public identifier and an URL.
the XML file contains some   entities (defined in the DTD but
apparently libxml is not trying to fetch the URL).

Both DOM and SimpleXML fill my window with warnings like:

Warning: DOMDocument::load() [function.load]: Entity 'nbsp' not defined
in /usr/local/apache2/htdocs/livres/2841771172.xml, line: 79 in
/usr/local/apache2/htdocs/catalogue.php on line 67

although in the PHP file I have set all relevant properties to false:

$livre = new domDocument;
if (file_exists("livres/".$ref.".xml")) {

HOW CAN I AVOID those warnings??? [I'm close to a nervous breakdown]


----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==---- The #1 Newsgroup Service in the World! 120,000+
----= East and West-Coast Server Farms - Total Privacy via Encryption =----

Re: Problem with "undefined entities" using DOM

Hi Harry Potter,
Here is the copy-paste from a post in User Contributed Notes of the
online php manual, that should give you an acceptable solution to your
problem. Basically, you have to include your DTD in the XML document
as an internal reference and set resolveExternals to TRUE. That's what
I use and it works well.

[dave at guidedvision dot com]
[31-Aug-2004 06:17]
[ manual > DOM]

  To load external entities from a doctype declaration set the member
  resolveExternals to true. This is useful for including character
entities in your custom xml documents.

For example:
$xml = <<<XML
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE page SYSTEM " ">
<page>&nbsp; &oelig; &eacute;</page>
$dom = new domDocument();
$dom->resolveExternals = true;
echo $dom->saveXML();

Without setting resolveExternals to true the "&nbsp; &oelig; &eacute;"
are lost.

Site Timeline