啊安
啊安
  • 发布:2016-11-27 04:17
  • 更新:2016-11-28 08:14
  • 阅读:1267

请问怎么在HB解析XML

分类:HBuilder
function loadXmlFile(xmlFile)//xmlFile 是xml文件的地址  

{
var xmlDom = null;
if (window.ActiveXObject)//IE浏览器中读取xml文件
{
xmlDom = new ActiveXObject("Microsoft.XMLDOM ");
xmlDom.async="false ";
xmlDom.load(xmlFile);
}
else if(document.implementation && document.implementation.createDocument)
{
//.Firefox,Chrome 浏览器中读取xml文件 ,Chrome 需要开服务器才能访问
var xmlhttp = new window.XMLHttpRequest();
xmlhttp.open("GET", xmlFile, false);
xmlhttp.send(null);
xmlDom = xmlhttp.responseXML;

}  
else   
{  
    xmlDom = null;  
}  
return xmlDom;  

};

 var aaa=loadXmlFile("story/story1.xml");  
 console.log(aaa);  

试过三种JS的方法,都失败了,期间不知道什么原因,以上代码成功过。走的应该是CHROME浏览器的路线。

后来不知道什么原因,又失败了。
if(document.implementation && document.implementation.createDocument)
{
xmlDoc = document.implementation.createDocument("", "", null);
xmlDoc.async = false;
xmlDoc.load(xmlFile);

使用这种方法,xmlDoc.load()方法找不到,不知道为什么。

2016-11-27 04:17 负责人:无 分享
已邀请:
badfl

badfl - mui详细文档:http://ask.dcloud.net.cn/article/1039

可以使用MUI封装好的Ajax方法来获取XML
http://dev.dcloud.net.cn/mui/ajax/

该问题目前已经被锁定, 无法添加新回复