xmldtdxml-entities

Conflict with DTD


I have the feeling to really misunderstand the DTD with XML :

In an XML file (which has got a doctype) I include with an entity another XML file (which has also got a doctype). And my parser is angry about it.

I know the problem is the Doctype because if I remove it everything is okay. But I can do without it, I need a final file in XML by including others XML File.

Here is /datas.xml :

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE datas [
    <!ENTITY Path_datas SYSTEM "Path/datas.xml" >
]>
<datas>
    &Path_datas;
</datas>

and here is /Path/datas.xml :

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE oolodatas [
    <!ENTITY Local_DefaultProject_Box_datas SYSTEM "Local/DefaultProject/Box/datas.xml" >
]>
<datas>
    <box>
        LOL
    </box>
</datas>

So in a PHP file I do this :

$datas = simplexml_load_file(realpath('maforge/datas/datas.xml'), NULL, LIBXML_NOENT);
var_dump($datas->asXML());

and here the error I get :

SCREAM: Error suppression ignored for ( ! ) Warning: simplexml_load_file(): file:///C:/wamp/www/forge/Path/datas.xml:2: parser error : StartTag: invalid element name

Thanks you for your help !


Solution

  • A DOCTYPE declaration can appear only in the main XML document (the "document entity"), not in an included document (an "external entity").