[英]Javascript to print a string which has xml contents
I have a variable in javascript which has XML data. 我在javascript中有一个包含XML数据的变量。 When I try to print it, it prints only values of XML data and doesn't print XML tags.
当我尝试打印它时,它只打印XML数据的值而不打印XML标记。
I have this function: 我有这个功能:
function printxml(xmlData,requestTag) {
var myWindow=window.open('');
myWindow.document.write("<div id='hii'>+"xmlData+"<div>");
}
Where xmldata
contains: xmldata
包含的位置:
<?xml version="1.0" encoding="UTF-8"?>
<book>
<author>Sindhu</author>
<BookName>BookName</BookName>
</book>
It prints only 它只打印
SindhuBookName
I am no Javascript expert, but I guess this is because your browser won't show you what it considers HTML tags. 我不是Javascript专家,但我想这是因为您的浏览器不会向您显示它认为的HTML标签。 I think that you need to escape them, so that you can see the whole XML string.
我认为您需要转义它们,以便您可以看到整个XML字符串。
Try this : https://stackoverflow.com/a/5251551/2466911 试试这个: https : //stackoverflow.com/a/5251551/2466911
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.