我在通过 javascript 中的 E4x 检索属性值时遇到问题。
假设如下 XML 节点列表作为 XMLObject:
<node att1="value1" att2="value2" att3="value3" att4="value4">
<nodeChild><!CDATA[/* ... */]></nodeChild>
/* more node childs */
</node>
我使用以下方法正确访问了节点(在循环中)及其属性节点attributes()
:
var attributes = node[n].attributes() ;
for(var n = 0 ; n < attributes.length() ; n++) {
var name = attributes[n].name() ;
var value = attributes[n].toString() ;
//.. handle the values
}
现在,一方面,名称和值没有充分返回 value(n) 返回 name(n+1) 的值,即 的值att1
将是value2
; 如果我设置var value = attributes[ (n+1) ].toString()
的值正确返回但第一个值将返回undefined
。
可能我只是对这个很感兴趣。那么,是否有人对我所缺少的有任何指示?
TIA,
FK