IE9 NOT getting 'children' of XML node
IE9 NOT getting 'children' of XML node
我在javascript中有一个名为RoomPriceInfo的变量:
<?xml version="1.0" encoding="UTF-8"?>
<BkgItemHotelRoomPrices CurrCode="EUR">
<RoomType Code="DB" Count="1" Desc="Double" Age="0">
<PriceInfo EndDate="2011-12-17" AgentMarkup="0.0" MarkupPerc="0.1075" FitRdg="0.25" MarkupPrice="48.73" AgentPrice="48.75" StartDate="2011-12-11" Nights="7" FitRdgPrice="48.75" CurrDec="2" CurrDecPrice="48.75" SuppPrice="44.0"/>
</RoomType>
</BkgItemHotelRoomPrices>
和以下代码:
DBRoomPrice = RoomPriceInfo.doXPath("//RoomType[@Code='DB']");
alert(DBRoomPrice[0].children.length);
在Ubuntu的FF7和WinXP的FF8下,我得到1的警报,这是正确的。然而,在WinXP的IE8和Windows 7的IE9下,什么都不会发生。它只是静静地死去。
有人能解释一下吗?如果我在DOM对象上做一个getElementById
然后请求它的子对象,那么IE8 &
Internet Explorer(包括版本11!)不支持XML元素的.children
属性。
如果您想获得子元素的数量,使用element.childElementCount
(IE9+):
element.children.length; // Does not work in IE on XML elements
element.childElementCount; // Works in every browser
如果您只想知道一个元素是否有任何子元素,您还可以检查element.firstElementChild
(或element.lastElementChild
)是否不为空。在IE9+中支持此属性:
element.children.length === 0; // All real browsers
element.firstElementChild !== null; // IE 9+
如果要遍历XML节点的所有子元素,请使用childNodes
并通过nodeType
:
for (var i = 0, len = element.childNodes.length; i < l; ++i) {
var child = element.childNodes[i];
if (child.nodeType !== 1/*Node.ELEMENT_NODE*/) continue;
// Now, do whatever you want with the child element.
}
这可能解决不了问题,但是…您应该使用childNodes而不是children属性来访问子节点。我不确定哪一个更好,但我知道肯定childNodes是广泛支持的。也许微软也是这样做的?!
相关文章:
- 如何在Node.js中根据XML验证DTD
- 如何在node.js中返回与URL请求相对应的XML文件
- 带有ajax xml请求的Node js脚本不起作用
- 如何在 Node.js 中使用 rdflib.js 或 rdf-parser-rdfxml 解析 RDF/XML
- Node.js中的XML(使用javascript)
- 在 Node JS 中使用 fs-extra 更新 xml 文件
- jQuery:将 Xml Node 设置为 DOM 元素
- 在 Node.js 中保存 XML 文件
- node.js-从大型XML文件中提取XML片段
- 如何使用Node.js解析HTML/XML文档
- node.js中XML下载后的零字节文件
- 从url解析xml文件并循环使用node.js获取其中的所有url
- 我需要一种方法来获取一些json,并使用node.js将其转换为xml
- 是否存在一种默认机制来获取XML Node的平面字符串表示形式
- 在Node.js中读取XML文件
- IE9 NOT getting 'children' of XML node
- Node + xmldom:如何在javascript中更改单个XML字段的值
- Node.js/Javascript: mocha测试失败,测试将XML解析为JSON时超时
- 什么是最好的JSON或JS对象到XML转换模块的Node JS
- xml / Node not created