开发者

How to use external entities in XML?

I am trying to understand how to use external entities, but I am missing something.

I have a first file, test_entity.xml

<?xml version="1.0" enc开发者_如何学Pythonoding="UTF-8" ?>
<test>
    <test_1>Inside</test_1>
</test>

And a second file test_entity2.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE root [
    <!ENTITY test_entity SYSTEM "/Users/username/test_entity.xml">  
    <!ENTITY test_string "This is a test">
]>
<root>
    <tmp id="1">&test_entity;</tmp>
    <tmp id="2">&test_string;</tmp>
</root>

Here I am trying to embed test_entity.xml content into test_entity2.xml but the ouput looks like this :

<root>
    <tmp id="1"/>
    <tmp id="2">This is a test</tmp>
</root>

What am I missing ?

Update

I am displaying test_entity2.xml through firefox and chrome


What you are doing is valid XML and will work with XML parsers that adhere to the specs and are not hobbled by security restrictions.

Try viewing the XML in IE. Some browsers(like FireFox and Chrome) have very strict security settings and will not load files entity references and XSLT processing instructions that reference files on the filesystm.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜