Connecting Tech Pros Worldwide Forums | Help | Site Map

Problem with "undefined entities" using DOM

Harry Potter
Guest
 
Posts: n/a
#1: Jul 17 '05
Hi,

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;
$livre->strictErrorChecking=false;
$livre->resolveExternals=false;
$livre->substituteEntities=false;
if (file_exists("livres/".$ref.".xml")) {
$livre->load("livres/".$ref.".xml");
$titre=$livre->getElementsByTagName("titre")->item(0)->firstChild->nodeV
alue;

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

TIA

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

Jamais-Content
Guest
 
Posts: n/a
#2: Jul 17 '05

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.

</blockquote>
[dave at guidedvision dot com]
[31-Aug-2004 06:17]
[php.net 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:
<?php
$xml = <<<XML
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE page SYSTEM "http://gv.ca/dtd/character-entities.dtd">
<page>&nbsp; &oelig; &eacute;</page>
XML;
$dom = new domDocument();
$dom->resolveExternals = true;
$dom->loadXML($xml);
echo $dom->saveXML();
?>

Without setting resolveExternals to true the "&nbsp; &oelig; &eacute;"
are lost.
</blockquote>
Closed Thread


Similar PHP bytes