Why external system entities are not working for m

2020-04-20 17:50发布

问题:

I am attempting to replicate the example given in this answer:

https://stackoverflow.com/a/5127928/356011

that illustrates using external entities to include a fragment of XML file in another XML file.

doc.xml:

<?xml version="1.0" standalone="no" ?>
<!DOCTYPE doc [
        <!ENTITY otherFile SYSTEM "otherFile.xml">
        ]>
<doc>
    <foo>
        <bar>&otherFile;</bar>
    </foo>
</doc>

otherFile.xml:

<baz>this is my content</baz>

When I attempt to test this by opening doc.xml in any browser, I just get:

 <doc>
   <foo>
      <bar/>
    </foo>
 </doc>

rendered.

Shouldn't it be rendering the included file, as well?

回答1:

The reason it isn't working is that browsers don't fully support XML. They only support it with restrictions, such as "no external entities". I don't know why.