3 * Copyright(c) 2006-2010 Sencha Inc.
5 * http://www.sencha.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 root = xmlData.documentElement || xmlData;
45 node.appendChild(this.parseXml(root));
48 this.runCallback(callback, scope || node, [node]);
50 this.handleFailure(response);
55 parseXml : function(node) {
57 Ext.each(node.childNodes, function(n){
58 if(n.nodeType == this.XML_NODE_ELEMENT){
59 var treeNode = this.createNode(n);
60 if(n.childNodes.length > 0){
61 var child = this.parseXml(n);
62 if(typeof child == 'string'){
63 treeNode.attributes.innerText = child;
65 treeNode.appendChild(child);
70 else if(n.nodeType == this.XML_NODE_TEXT){
71 var text = n.nodeValue.trim();
82 createNode : function(node){
87 Ext.each(node.attributes, function(a){
88 attr[a.nodeName] = a.nodeValue;
91 this.processAttributes(attr);
93 return Ext.ux.tree.XmlTreeLoader.superclass.createNode.call(this, attr);
97 * Template method intended to be overridden by subclasses that need to provide
98 * custom attribute processing prior to the creation of each TreeNode. This method
99 * will be passed a config object containing existing TreeNode attribute name/value
100 * pairs which can be modified as needed directly (no need to return the object).
102 processAttributes: Ext.emptyFn
106 Ext.ux.XmlTreeLoader = Ext.ux.tree.XmlTreeLoader;