DOMDocument::load(): Namespace default prefix was not found in Entity

倾然丶 夕夏残阳落幕 提交于 2020-05-17 07:08:05

问题


I am parsing some XML with PHP DOMDocument. This is my code:

$doc = new DOMDocument;
$doc->resolveExternals = true;
$doc->substituteEntities = true;
$doc->load('../poems_xml/'.$pid.'.xml');

$xsl = new DOMDocument;
$xsl->load('../xslt/title.xsl');
$proc = new XSLTProcessor;
$proc->importStylesheet($xsl);
$ptitle = $proc->transformToXML($doc);

I have an entity file declared at the beginning of my .xml:

<?xml version="1.0" encoding="utf-8"?>
<?oxygen RNGSchema="../dtd/dps.rng" type="xml"?>
<?xml-stylesheet href="../dtd/dps.css" type="text/css"?>
<!DOCTYPE TEI SYSTEM "../dtd/entities.ent">
[...]

And the entities file looks like this:

[...]
<!ENTITY d1_AytR_002 "<rs key='d1_AytR_002'>d1_AytR_002</rs>">
[...]

In my .xml I use these entities like so:

...&d1_AytR_002;...

Now, it all goes well in terms of parsing the file and transform it via the xslt and css files, except for the entities. They just get ignored. Turning on the php_error_log flag, I get this:

Notice: DOMDocument::load(): Namespace default prefix was not found in Entity, line: 1 in index.php on line 28

(line 28 of index.php is where the load('../poems_xml/'.$pid.'.xml') instruction is). Can someone shed some light on what I should check/add regarding my entities?

I'm using PHP 5.6.40.


回答1:


A workaround (and possible permanent solution) is that of adding the namespace to each of the <!ENTITY>s, like so:

<!ENTITY d1_AytR_002 "<rs xmlns="http://www.tei-c.org/ns/1.0" key='d1_AytR_002'>d1_AytR_002</rs>">


来源:https://stackoverflow.com/questions/61530580/domdocumentload-namespace-default-prefix-was-not-found-in-entity

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!