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