Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

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

— asked March 17th 2010 by Mark Poston
  • childnodes
  • dom
  • issues
  • nodelist
  • problems
  • tidomelementproxy
  • xml
0 Comments

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

    — answered March 17th 2010 by Mark Poston
    permalink
    0 Comments
  • The spec says you need to use node.item(index) instead of node[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?

    — answered March 17th 2010 by Jeff Haynie
    permalink
    0 Comments
  • 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 (with childNodes.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

    — answered March 17th 2010 by Mark Poston
    permalink
    0 Comments
  • 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.

    — answered March 22nd 2010 by Jeff Haynie
    permalink
    0 Comments
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.