3 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
4 <title>The source code</title>
5 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
6 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
8 <body onload="prettyPrint();">
9 <pre class="prettyprint lang-js">/*!
10 * Ext JS Library 3.3.1
11 * Copyright(c) 2006-2010 Sencha Inc.
12 * licensing@sencha.com
13 * http://www.sencha.com/license
15 Ext.ns('Ext.ux.tree');
18 * @class Ext.ux.tree.XmlTreeLoader
19 * @extends Ext.tree.TreeLoader
20 * <p>A TreeLoader that can convert an XML document into a hierarchy of {@link Ext.tree.TreeNode}s.
21 * Any text value included as a text node in the XML will be added to the parent node as an attribute
22 * called <tt>innerText</tt>. Also, the tag name of each XML node will be added to the tree node as
23 * an attribute called <tt>tagName</tt>.</p>
24 * <p>By default, this class expects that your source XML will provide the necessary attributes on each
25 * node as expected by the {@link Ext.tree.TreePanel} to display and load properly. However, you can
26 * provide your own custom processing of node attributes by overriding the {@link #processNode} method
27 * and modifying the attributes as needed before they are used to create the associated TreeNode.</p>
29 * Creates a new XmlTreeloader.
30 * @param {Object} config A config object containing config properties.
32 Ext.ux.tree.XmlTreeLoader = Ext.extend(Ext.tree.TreeLoader, {
33 <div id="prop-Ext.ux.tree.XmlTreeLoader-XML_NODE_ELEMENT"></div>/**
34 * @property XML_NODE_ELEMENT
35 * XML element node (value 1, read-only)
39 <div id="prop-Ext.ux.tree.XmlTreeLoader-XML_NODE_TEXT"></div>/**
40 * @property XML_NODE_TEXT
41 * XML text node (value 3, read-only)
47 processResponse : function(response, node, callback){
48 var xmlData = response.responseXML,
49 root = xmlData.documentElement || xmlData;
53 node.appendChild(this.parseXml(root));
56 this.runCallback(callback, scope || node, [node]);
58 this.handleFailure(response);
63 parseXml : function(node) {
65 Ext.each(node.childNodes, function(n){
66 if(n.nodeType == this.XML_NODE_ELEMENT){
67 var treeNode = this.createNode(n);
68 if(n.childNodes.length > 0){
69 var child = this.parseXml(n);
70 if(typeof child == 'string'){
71 treeNode.attributes.innerText = child;
73 treeNode.appendChild(child);
78 else if(n.nodeType == this.XML_NODE_TEXT){
79 var text = n.nodeValue.trim();
90 createNode : function(node){
95 Ext.each(node.attributes, function(a){
96 attr[a.nodeName] = a.nodeValue;
99 this.processAttributes(attr);
101 return Ext.ux.tree.XmlTreeLoader.superclass.createNode.call(this, attr);
105 * Template method intended to be overridden by subclasses that need to provide
106 * custom attribute processing prior to the creation of each TreeNode. This method
107 * will be passed a config object containing existing TreeNode attribute name/value
108 * pairs which can be modified as needed directly (no need to return the object).
110 processAttributes: Ext.emptyFn
114 Ext.ux.XmlTreeLoader = Ext.ux.tree.XmlTreeLoader;