我有 XML 字符串,我必须将其加载到 DOM 文档。 我已经尝试过这个:
if ($window.DOMParser)
{
parser=new $window.DOMParser();
xml=parser.parseFromString(data,"application/xml");
}
else // Internet Explorer
{
xml=new ActiveXObject("Microsoft.XMLDOM");
xml.async=false;
xml.loadXML(data);
}
但是在 Angular Controller.js 上它不起作用! 我得到了这个:
<body xmlns="http://www.w3.org/1999/xhtml"><parsererror style="display: block; white-space: pre; border: 2px solid #c77; padding: 0 1em 0 1em; margin: 1em; background-color: #fdd; color: black"><h3>This page contains the following errors:</h3><div style="font-family:monospace;font-size:12px">error on line 1 at column 1: Document is empty
</div><h3>Below is a rendering of the page up to the first error.</h3></parsererror></body>
感谢您的提前。
最佳答案
我已经将 Angular 调用更改为 XML 调用,并且不必解析对文档的响应,因为他... 我的电话看起来像:
$http({
method : 'GET',
url : "http://localhost:8080/getXML",
timeout : 10000,
params : {
fileName: fileName
},
transformResponse : function(data) {
return $.parseXML(data);
}
}).success(function(data) {
// data = document object
});
我从 API 返回一个有效的 XML 字符串,并在 @RequestMapping 上的 Spring 上定义了返回类型以生成 = MediaType.APPLICATION_XML_VALUE。 希望它对您也有帮助。
关于javascript - AngularJS:将 XML 字符串加载到 XML 文档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31648945/