View Full Version : Question aboutXML Tree - how to detect leaf nodes without a leaf attribute

12 Apr 2010, 5:11 AM
I'm working on an Ext-based tool to edit XML documents in tree format. I've looked over the code for the XMLTreeLoader example (http://www.extjs.com/deploy/dev/examples/tree/xml-tree-loader.html), and I'm trying to figure out how I can test whether a given node is a leaf. In the example code, this is how it's done:

else if(attr.title){ // is it a book node?

// irrelevant code removed

attr.leaf = true;
In the sample XML document, the leaf nodes are identified as all nodes with the "title" attribute. What if I don't want to have a special attribute that identifies leaf nodes? Is there any way I can just test nodes to see if they have any child nodes inside them? It appears that the XMLTreeLoader code depends solely on the presence of the "title" attribute to figure out whether a given node is a leaf node.

I want to have a bunch of nodes with the same tagname and attributes nested inside each other, and the only difference between leaf nodes and other nodes would be that the leaf nodes have no children. Is it possible to process a document like this with the Ext XMLTreeLoader? Any help is appreciated, thanks.

For convenience's sake, here are the relevant code files.
Here is the XMLTreeLoader base class: http://www.extjs.com/deploy/dev/examples/ux/XmlTreeLoader.js
And here is the XMLTreeLoader class extension that interprets the book/author data XML file: http://www.extjs.com/deploy/dev/examples/tree/xml-tree-loader.js

12 Apr 2010, 5:47 AM
The Node object has a method : hasChildNodes()

12 Apr 2010, 6:03 PM
Thanks, but the node object in the XML example is defined based only on the attributes in the XML tags. If you look at the code, the child status of each node is set in the processAttributes function, which determines each node's status based solely on the attributes within the tag.