Upgrade to ExtJS 4.0.0 - Released 04/26/2011
[extjs.git] / src / data / XmlStore.js
1 /**
2  * @author Ed Spencer
3  * @class Ext.data.XmlStore
4  * @extends Ext.data.Store
5  * @private
6  * @ignore
7  * <p>Small helper class to make creating {@link Ext.data.Store}s from XML data easier.
8  * A XmlStore will be automatically configured with a {@link Ext.data.reader.Xml}.</p>
9  * <p>A store configuration would be something like:<pre><code>
10 var store = new Ext.data.XmlStore({
11     // store configs
12     autoDestroy: true,
13     storeId: 'myStore',
14     url: 'sheldon.xml', // automatically configures a HttpProxy
15     // reader configs
16     record: 'Item', // records will have an "Item" tag
17     idPath: 'ASIN',
18     totalRecords: '@TotalResults'
19     fields: [
20         // set up the fields mapping into the xml doc
21         // The first needs mapping, the others are very basic
22         {name: 'Author', mapping: 'ItemAttributes > Author'},
23         'Title', 'Manufacturer', 'ProductGroup'
24     ]
25 });
26  * </code></pre></p>
27  * <p>This store is configured to consume a returned object of the form:<pre><code>
28 &#60?xml version="1.0" encoding="UTF-8"?>
29 &#60ItemSearchResponse xmlns="http://webservices.amazon.com/AWSECommerceService/2009-05-15">
30     &#60Items>
31         &#60Request>
32             &#60IsValid>True&#60/IsValid>
33             &#60ItemSearchRequest>
34                 &#60Author>Sidney Sheldon&#60/Author>
35                 &#60SearchIndex>Books&#60/SearchIndex>
36             &#60/ItemSearchRequest>
37         &#60/Request>
38         &#60TotalResults>203&#60/TotalResults>
39         &#60TotalPages>21&#60/TotalPages>
40         &#60Item>
41             &#60ASIN>0446355453&#60/ASIN>
42             &#60DetailPageURL>
43                 http://www.amazon.com/
44             &#60/DetailPageURL>
45             &#60ItemAttributes>
46                 &#60Author>Sidney Sheldon&#60/Author>
47                 &#60Manufacturer>Warner Books&#60/Manufacturer>
48                 &#60ProductGroup>Book&#60/ProductGroup>
49                 &#60Title>Master of the Game&#60/Title>
50             &#60/ItemAttributes>
51         &#60/Item>
52     &#60/Items>
53 &#60/ItemSearchResponse>
54  * </code></pre>
55  * An object literal of this form could also be used as the {@link #data} config option.</p>
56  * <p><b>Note:</b> Although not listed here, this class accepts all of the configuration options of
57  * <b>{@link Ext.data.reader.Xml XmlReader}</b>.</p>
58  * @constructor
59  * @param {Object} config
60  * @xtype xmlstore
61  */
62 Ext.define('Ext.data.XmlStore', {
63     extend: 'Ext.data.Store',
64     alternateClassName: 'Ext.data.XmlStore',
65     alias: 'store.xml',
66
67     /**
68      * @cfg {Ext.data.DataReader} reader @hide
69      */
70     constructor: function(config){
71         config = config || {};
72         config = config || {};
73
74         Ext.applyIf(config, {
75             proxy: {
76                 type: 'ajax',
77                 reader: 'xml',
78                 writer: 'xml'
79             }
80         });
81
82         this.callParent([config]);
83     }
84 });