XML DOM childNodes issue?
Hi,
Can anyone confirm that there is an issue with the childNodes property in the XML support?
I get an error: [TiDOMElementProxy kind]: unrecognized selector sent to instance.
This seems to occur when I make a node list. I can access the nodeList length but not the nodes within it.
Regards
Mark
4 Answers
-
node.nextSibling
also seems not to return anything. For example:node.firstChild.nextSibling.getAttribute("id")
nor
node2 = node1.firstChild; var idValue = node2.nextSibling.getAttribute("id");
Mark
-
The spec says you need to use
node.item(index)
instead ofnode[index]
. Browsers seem to provide shortcut for this but we are implementing based on the spec.Otherwise, can you post snippet of code to explain?
-
Hi Jeff,
I am using nodeList.item() and this seems to work ok (i think) if I am creating a nodeList that is directly based on the documentElement, but if I create a a nodeList from another node then this will fail.Here's a snippet of a node walker function I was trying to write (based on my second message here:
elements = doc.getElementsByTagName("nodes"); function nodewalker(node) { alert("att: " + node.getAttribute("id")); for (var i=0;i<node.childNodes.length;i++) { if (i==0) { nodewalker(node.firstChild) } else { var n = node.firstChild; for (var x=0;x<i;x++) { n = n.nextSibling; } nodewalker(n); } } }; nodewalker(elements.item(0));
the XML I am using is:
<nodes id="0"> <node id="1"> <node id="2"> <node id="3"/> </node> <node id="4"> <node id="5"/> </node> <node id="6"> <node id="7"/> </node> </node> <node id="8"> <node id="9"> <node id="10"/> </node> </node> <node id="11"> <node id="12"> <node id="13"/> </node> </node> </nodes>
This example will return 0,1,2,3 in the alerts as firstChild seems to work OK but fails to get the nextSibling nodes, and therefore will not return 4-13.
I can use childNodes.length here too, but accessing the child nodes (withchildNodes.item()
) themselves will fail with the error I mentioned above. Same applies if I create a separate nodelist:nodeList = myNode.childNodes
It seems that much of the DOM's methods are not returning results as they should be.
Regards
Mark -
OK - I think I have fixed all of these related to these issues with this ticket.
This fixes will be in tomorrow's 1.1 release.