3 * Copyright(c) 2006-2010 Ext JS, LLC
5 * http://www.extjs.com/license
10 * @class Ext.ux.tree.XmlTreeLoader
11 * @extends Ext.tree.TreeLoader
12 * <p>A TreeLoader that can convert an XML document into a hierarchy of {@link Ext.tree.TreeNode}s.
13 * Any text value included as a text node in the XML will be added to the parent node as an attribute
14 * called <tt>innerText</tt>. Also, the tag name of each XML node will be added to the tree node as
15 * an attribute called <tt>tagName</tt>.</p>
16 * <p>By default, this class expects that your source XML will provide the necessary attributes on each
17 * node as expected by the {@link Ext.tree.TreePanel} to display and load properly. However, you can
18 * provide your own custom processing of node attributes by overriding the {@link #processNode} method
19 * and modifying the attributes as needed before they are used to create the associated TreeNode.</p>
21 * Creates a new XmlTreeloader.
22 * @param {Object} config A config object containing config properties.
24 Ext.ux.tree.XmlTreeLoader = Ext.extend(Ext.tree.TreeLoader, {
26 * @property XML_NODE_ELEMENT
27 * XML element node (value 1, read-only)
32 * @property XML_NODE_TEXT
33 * XML text node (value 3, read-only)
39 processResponse : function(response, node, callback){
40 var xmlData = response.responseXML;
41 var root = xmlData.documentElement || xmlData;
45 node.appendChild(this.parseXml(root));
48 if(typeof callback == "function"){
52 this.handleFailure(response);
57 parseXml : function(node) {
59 Ext.each(node.childNodes, function(n){
60 if(n.nodeType == this.XML_NODE_ELEMENT){
61 var treeNode = this.createNode(n);
62 if(n.childNodes.length > 0){
63 var child = this.parseXml(n);
64 if(typeof child == 'string'){
65 treeNode.attributes.innerText = child;
67 treeNode.appendChild(child);
72 else if(n.nodeType == this.XML_NODE_TEXT){
73 var text = n.nodeValue.trim();
84 createNode : function(node){
89 Ext.each(node.attributes, function(a){
90 attr[a.nodeName] = a.nodeValue;
93 this.processAttributes(attr);
95 return Ext.ux.tree.XmlTreeLoader.superclass.createNode.call(this, attr);
99 * Template method intended to be overridden by subclasses that need to provide
100 * custom attribute processing prior to the creation of each TreeNode. This method
101 * will be passed a config object containing existing TreeNode attribute name/value
102 * pairs which can be modified as needed directly (no need to return the object).
104 processAttributes: Ext.emptyFn
108 Ext.ux.XmlTreeLoader = Ext.ux.tree.XmlTreeLoader;