Internet Explorer / MS Edge浏览器在遍历xml数据时出现问题
Internet Explorer / MS Edge browser issue traversing xml data
我正试图遍历一段XML来为web应用程序拉一些逻辑规则。我已经设法让我的JavaScript在Firefox, Chrome, Opera和Safari上工作,但我在MS浏览器中得到控制台错误,说明'无法获得未定义或空引用的属性'长度''。
我无法通过反复试验得到解决方案,因为错误出现在代码的早期。
Javascript示例;
function conditionTrigger(id, callType) {
var parser = new DOMParser(),
xmlLogic = parser.parseFromString(configXML, "text/xml"),
tags = xmlLogic.getElementsByTagName('*'),
conditionsPassed = 0,
callType;
if (id.length >= 3) {
id = id.slice(3);
}
console.log(tags[0]);
console.log(tags[0].children.length);
console.log('ID to be checked against = ' + id);
console.log(tags.length + ' nodes.');
console.log(tags[0].children.length + ' level 1 node children.');
for(var i01 = 0; i01 < tags[0].children.length; i01++ ){
console.log(tags[0].children[i01]);
if (tags[0].children[i01].nodeName == "Rules"){
console.log(tags[0].children[i01].children.length + ' child nodes of ' +tags[0].children[i01].nodeName + '.');
for(var i02 = 0; i02 < tags[0].children[i01].children.length; i02++){
console.log(tags[0].children[i01].children[i02]);
}
}
}
}
我的xml在下面;
<?xml version="1.0" encoding="utf-8" ?>
<output brand="[BRANDNAME]" title="[SCRIPTNAME]" version ="[SCRIPTVERSION]">
<Rules>
<block id="1000000" triggerID="14">
<ConditionsAndActions name="Test for something else" setIndex="2">
<Conditions>
<Condition type="DataField" fieldID="6" value="xxx" />
</Conditions>
<Actions>
<Action actionIndex="0" type="DisplayAlert" message="can't move on, xxx found"/>
</Actions>
</ConditionsAndActions>
<ConditionsAndActions name="Check if forename is 'test' and call is a callback" setIndex="1">
<Conditions>
<Condition type="DataField" fieldID="6" value="test" />
<Condition type="Callback" />
</Conditions>
<Actions>
<Action actionIndex="0" type="MoveToPanel" panelID="27"/>
<Action actionIndex="0" type="DisplayAlert" message="Aha, this is a callback!"/>
</Actions>
</ConditionsAndActions>
<ConditionsAndActions name="Default" setIndex="0">
<Conditions>
</Conditions>
<Actions>
<Action actionIndex="0" type="MoveToPanel" panelID="17"/>
</Actions>
</ConditionsAndActions>
</block>
<block id="1000001" triggerID="19">
<ConditionsAndActions name="Default" setIndex="0">
<Conditions>
</Conditions>
<Actions>
<Action actionIndex="0" type="MoveToPanel" panelID="18"/>
</Actions>
</ConditionsAndActions>
</block>
<block id="1000002" triggerID="20">
<ConditionsAndActions name="Default" setIndex="0">
<Conditions>
</Conditions>
<Actions>
<Action actionIndex="0" type="MoveToPanel" panelID="10"/>
</Actions>
</ConditionsAndActions>
</block>
<block id="1000003" triggerID="22">
<ConditionsAndActions name="Default" setIndex="0">
<Conditions>
</Conditions>
<Actions>
<Action actionIndex="0" type="MoveToPanel" panelID="10"/>
</Actions>
</ConditionsAndActions>
</block>
<block id="1000004" triggerID="23">
<ConditionsAndActions name="Default" setIndex="0">
<Conditions>
</Conditions>
<Actions>
<Action actionIndex="0" type="MoveToPanel" panelID="17"/>
</Actions>
</ConditionsAndActions>
</block>
</Rules>
</output>
我发现通过将。children更改为。childnodes和getAttribute来使用jquery。问题解决后
相关文章:
- 带有显示XML数据的HTML的空白页
- 要使用XML显示的静态数据
- 使用AJAX传递的数据编辑XML文件-正在删除XML数据
- 在HTML文档中使用XML文件中的数据
- 可以't从xml文件中提取数据
- 通过JS/AAJAX在XML文件中搜索1个数据
- 缩略图库的XML数据图像绑定
- 在Drupal7中扩展字段集时,修改collapse.js以从xml获取附加数据
- 使用Javascript分析XML对象数组中的数据
- 如何在剪切/粘贴/移动后在contentEditable DIV中保留与XML相关的数据
- 如何在Javascript中通过POST请求发送XML数据
- jQuery使用XML数据更新UL列表
- 将 XML 数据转换为 json 格式 AngularJS
- 如何在javascript(ajax)中使用嵌入HTML中的XML数据
- 从表单字段复制数据并将其放在echo语句中,所有这些都在$xml=simplexmlload_file函数中
- 当数据类型为XML时,如何将url参数传递给AJAX jquery
- 无法将确切的数据从XML获取到JavaScript中
- 使用JSONPjquery获取HTML格式的XML数据
- 如何在jquery中将xml解析数据获取为全局变量
- 将普通数据转换为xml数据的图像滑块