如何在javascript中显示xml? [英] how to display xml in javascript?
问题描述
正如问题所说,它只是逃避了我的记忆如何在javascript中显示xml,我想在页面上的div中显示一些源xml,它位于另一个div中xml的处理结果旁边。
As the question says, it just escaped my memory how to display xml in javascript, I want to display some source xml within an div on a page, that sits next to the processed result of the xml in another div.
不记得是否有相当于javascript的转义来转换客户端上的实体
Can't remember if there was an equivalent to javascript's escape to convert entities on the client
注意:xml文件按原样从服务器提供,因此我需要一个客户端解决方案
Note: the xml files are served as is from the server, so I need a client side solution
注意:主要问题XML在大多数浏览器中无法正确呈现,所有括号和属性都会消失,留下的文本看起来不像xml
Note: the main problem is XML doesn't render correctly in most browsers, all the brackets and attributes disappear, leaving you with text that doesn't look like xml
推荐答案
如果您希望浏览器将 XML
呈现 XML ,必须在它自己的文档中,如 iframe
或框架
。 DIV
将无法胜任!
If you want the browser to render your XML
as XML
, it must be in it's own document, like an iframe
, or a frame
. DIV
won't do the job!
此外,在 HTTP
提供 iframe
的请求的标头你应该发送 Content-Type:text / xml
,所以浏览器可以理解这个内容是 XML
。
Besides, in the HTTP
header of the request that serves the iframe
you should send Content-Type: text/xml
, so the Browser can understand that this content is an XML
.
但是,如果你真的需要在DIV你必须自己构建一个 XML
渲染函数 XML2HTML
。您可以使用 HTML
PRE
标记,如果您的 XML
字符串已经格式化(换行符和制表符)。在这种情况下,您必须在 XML中将
字符串。<
替换为& gt;
But, if you truely need to see it in a DIV you will have to build yourself an XML
rendering function XML2HTML
. You can use the HTML
PRE
tag for that, if your XML
string is already formatted (line breaks and tabs). In that case you will have to replace <
to >
in the XML
string.
结论: 浏览器
可以' t在同一文档中呈现 XML
和 HTML
。如果您需要它,您只需要解决它。
Conclusion: The browser
can't render XML
and HTML
in the same document. If you need it, you just have to workaround it.
这篇关于如何在javascript中显示xml?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!