1

I'm trying to load XML files from the PHP repository of the online documentation. It's by the DocBook standard.

However, when I load an XML file I get errors like:

Warning: DOMDocument::load(): Entity 'reftitle.intro' not defined

I somewhat understand that error, but I'm having problems to fix it. I tried with the external entities loader callback (libxml_set_external_entity_loader) but it's only called once, for the file itself.

So somehow I think I need to tell DOMDocument either a) to ignore those undefined entities or b) to provide these entities.

There is a file named language-defs.ent which contains all these entities like inside a DTD, e.g.:

<!ENTITY reftitle.intro        '<title xmlns="http://docbook.org/ns/docbook">Introduction</title>'>

But I don't know how to make use of that. Maybe it's just the time of the day.

PeeHaa
  • 71,436
  • 58
  • 190
  • 262
hakre
  • 193,403
  • 52
  • 435
  • 836

1 Answers1

0

Roughly for the moment as I have no clue why, however (one might be already enough):

$fake = '<?xml version="1.0"?>
<!DOCTYPE book [
<!ENTITY % myent SYSTEM "file:///c:/path%20to/phpdoc-en-svn/extensions.ent">
%myent;
<!ENTITY % myent SYSTEM "file:///c:/path%20to/phpdoc-en-svn/language-defs.ent">
%myent;
<!ENTITY % myent SYSTEM "file:///c:/path%20to/phpdoc-en-svn/language-snippets.ent">
%myent;
]>';

and then (all XML $file come with a XML declaration that needs to be removed):

$doc = new DOMDocument();
$buffer = file_get_contents($file);
libxml_use_internal_errors(true);
$result = $doc->loadXML($fake.strstr($buffer, "\n"));

and it then works. It still has errors, hence the libxml_use_internal_errors, however the XML files are loading.

Not all entities are resolved.

hakre
  • 193,403
  • 52
  • 435
  • 836