javascript - JS获取指定类型的XML节点

标签 javascript xml

JavaScript 中是否有任何内置函数只获取元素节点,或者我是否必须添加另一个循环来计算这些节点的实际数量(如果我之前需要它),例如:

l = 0;
for(i = 0; i < x.childNodes.length; i++){
    if(x.childNodes[i].nodeType = 1) l++;       
}

for(i = 0; i < x.childNodes.length; i++){
    if(x.childNodes[i].nodeType != 1) continue;
    new Something(l);   
}

最佳答案

Node.children is a read-only property that returns a live HTMLCollection of the child elements of Node.

语法

var elList = elementNodeReference.children; 

elList is a HTMLCollection, which is an ordered collection of DOM elements that are children of elementNodeReference. If there are no element children, then elList contains no elements and has a length of 0.

关于javascript - JS获取指定类型的XML节点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32415464/

相关文章:

android - 二进制 XML 文件行 #23 : Error inflating class TextView

xml - XSD 设计模式

javascript - 三.js |导入的 Blender 模型就像是低质量渲染的

javascript - 使用 Ajax 和 PHP 将数据发送到 MySQL 但没有任何反应

javascript - 根据复选框状态启用/禁用输入字段

javascript - restivus.d.ts 的 TypeScript 定义

javascript - 为 jQuery UI Droppable 的 Intersect tolerance 构建匹配选项

java - 系统服务不可用异常SimpleAdapter Android

xml - 为什么 < 不转换为 < while > 和其他转义字符适当转换

javascript - 从 Javascript 读取具有不同标记名的 XML