如何在XHTML文档中嵌入XML文档? [英] How can I embed a XML document inside a XHTML document?

查看:117
本文介绍了如何在XHTML文档中嵌入XML文档?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,如何嵌入

<?xml version="1.0" encoding="utf-8"?>
<root>
    <node><![CDATA[Text]]></node>
</root>

在我的XHTML中?

我知道我可以将其放在CDATA部分中。

I know I can put it in a CDATA section...

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
  "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<title>My title</title>
</head>
<body>
<p>I am a XHTML paragraph!</p>
<div>
    <![CDATA[
    <?xml version="1.0" encoding="utf-8"?>
    <root>
        <node>Text</node>
    </root>
    ]]>
</div>
</body>
</html>

...但是我必须删除XML文件的CDATA部分,然后将XML解析为文本

... but then I have to remove XML file's CDATA sections and the XML is parsed as text instead of XML.

然后,我得到这个...

Then, I get this...

...但是我想要这样的东西:

... but I want something like this:

推荐答案

请注意,CDATA只是转义字符的一种方法,而不是嵌入的方法。现在进入您的问题:

Please be aware that CDATA is just a way to escape characters, not a method of embedding. Now on to your question:

据我所知,嵌入XML文件的唯一方法是使用对象标记或iframe:

As far as I know, the only way to embed an XML file would be using the object tag or an iframe:

<!-- Keep in mind that iframe is invalid in XHTML 1.0 and 1.1.-->
<iframe src="data:application/xml,&lt;root&gt;&lt;node&gt;Text&lt;/node&gt;&lt;/root&gt;"/>
<!-- When using `data:mime/type,[data]' the type attribute is overriden -->
<object data="data:application/xml,&lt;root&gt;&lt;node&gt;Text&lt;/node&gt;&lt;/root&gt;"/>

这里的问题是某些浏览器只会将XML的内容显示为内联文本,而其他浏览器将显示一个XML查看器窗口,这可能是您想要的。

The issue here is that some browsers will just display the contents of the XML as inline text, while others will display with an XML viewer window, which is likely what you want.

以下是图表:


   layout engine (browser)    |   <object>    |   <iframe>
 ----------------------------------------------------------
  Gecko (Firefox)             |  inline text  |  XML viewer
  Webkit (Safari / new Opera) |  inline text  |  inline text
  Blink (Chrome/Chromium)     |  inline text  |  inline text
  Presto (old Opera)          |  XML Viewer   |  XML viewer
  Trident (IE5-IE8)           |  inline text  |  XML Viewer

由于替换了presto,因此只有iframe + firefox是您唯一可行的组合。

Since presto is being replaced, you're left with iframe+firefox as your only workable combination.

如果某人可以使用IE进行测试,请在表格中编辑您的结果。

If someone can test with IE, please edit-in a your results into the table.

这篇关于如何在XHTML文档中嵌入XML文档?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆