3 <title>The source code</title>
\r
4 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
\r
5 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
\r
7 <body onload="prettyPrint();">
\r
8 <pre class="prettyprint lang-js">Ext.ns('Ext.ux.tree');
10 <div id="cls-Ext.ux.tree.XmlTreeLoader"></div>/**
11 * @class Ext.ux.tree.XmlTreeLoader
12 * @extends Ext.tree.TreeLoader
13 * <p>A TreeLoader that can convert an XML document into a hierarchy of {@link Ext.tree.TreeNode}s.
14 * Any text value included as a text node in the XML will be added to the parent node as an attribute
15 * called <tt>innerText</tt>. Also, the tag name of each XML node will be added to the tree node as
16 * an attribute called <tt>tagName</tt>.</p>
17 * <p>By default, this class expects that your source XML will provide the necessary attributes on each
18 * node as expected by the {@link Ext.tree.TreePanel} to display and load properly. However, you can
19 * provide your own custom processing of node attributes by overriding the {@link #processNode} method
20 * and modifying the attributes as needed before they are used to create the associated TreeNode.</p>
22 * Creates a new XmlTreeloader.
23 * @param {Object} config A config object containing config properties.
25 Ext.ux.tree.XmlTreeLoader = Ext.extend(Ext.tree.TreeLoader, {
26 <div id="prop-Ext.ux.tree.XmlTreeLoader-XML_NODE_ELEMENT"></div>/**
27 * @property XML_NODE_ELEMENT
28 * XML element node (value 1, read-only)
32 <div id="prop-Ext.ux.tree.XmlTreeLoader-XML_NODE_TEXT"></div>/**
33 * @property XML_NODE_TEXT
34 * XML text node (value 3, read-only)
40 processResponse : function(response, node, callback){
41 var xmlData = response.responseXML;
42 var root = xmlData.documentElement || xmlData;
46 node.appendChild(this.parseXml(root));
49 if(typeof callback == "function"){
53 this.handleFailure(response);
58 parseXml : function(node) {
60 Ext.each(node.childNodes, function(n){
61 if(n.nodeType == this.XML_NODE_ELEMENT){
62 var treeNode = this.createNode(n);
63 if(n.childNodes.length > 0){
64 var child = this.parseXml(n);
65 if(typeof child == 'string'){
66 treeNode.attributes.innerText = child;
68 treeNode.appendChild(child);
73 else if(n.nodeType == this.XML_NODE_TEXT){
74 var text = n.nodeValue.trim();
85 createNode : function(node){
90 Ext.each(node.attributes, function(a){
91 attr[a.nodeName] = a.nodeValue;
94 this.processAttributes(attr);
96 return Ext.ux.tree.XmlTreeLoader.superclass.createNode.call(this, attr);
100 * Template method intended to be overridden by subclasses that need to provide
101 * custom attribute processing prior to the creation of each TreeNode. This method
102 * will be passed a config object containing existing TreeNode attribute name/value
103 * pairs which can be modified as needed directly (no need to return the object).
105 processAttributes: Ext.emptyFn
109 Ext.ux.XmlTreeLoader = Ext.ux.tree.XmlTreeLoader;