X-Git-Url: http://git.ithinksw.org/extjs.git/blobdiff_plain/c930e9176a5a85509c5b0230e2bff5c22a591432..7a654f8d43fdb43d78b63d90528bed6e86b608cc:/docs/api/Ext.data.reader.Xml.html diff --git a/docs/api/Ext.data.reader.Xml.html b/docs/api/Ext.data.reader.Xml.html new file mode 100644 index 00000000..f10d2288 --- /dev/null +++ b/docs/api/Ext.data.reader.Xml.html @@ -0,0 +1,265 @@ +Ext.data.reader.Xml | Ext JS 4.0 Documentation +
For up to date documentation and features, visit +http://docs.sencha.com/ext-js/4-0

Sencha Documentation

+ + + + + +

Hierarchy

Ext.data.reader.Reader
Ext.data.reader.Xml

The XML Reader is used by a Proxy to read a server response that is sent back in XML format. This usually +happens as a result of loading a Store - for example we might create something like this:

+ + + + +
Ext.define('User', {
+    extend: 'Ext.data.Model',
+    fields: ['id', 'name', 'email']
+});
+
+var store = new Ext.data.Store({
+    model: 'User',
+    proxy: {
+        type: 'ajax',
+        url : 'users.xml',
+        reader: {
+            type: 'xml',
+            record: 'user'
+        }
+    }
+});
+
+ + + + +

The example above creates a 'User' model. Models are explained in the Model docs if you're +not already familiar with them.

+ + + + +

We created the simplest type of XML Reader possible by simply telling our Store's +Proxy that we want a XML Reader. The Store automatically passes the configured model to the +Store, so it is as if we passed this instead: + +

reader: {
+    type : 'xml',
+    model: 'User',
+    record: 'user'
+}
+
+ +

The reader we set up is ready to read data from our server - at the moment it will accept a response like this:

+ +
<?xml version="1.0" encoding="UTF-8"?>
+<user>
+    <id>1</id>
+    <name>Ed Spencer</name>
+    <email>ed@sencha.com</email>
+</user>
+<user>
+    <id>2</id>
+    <name>Abe Elias</name>
+    <email>abe@sencha.com</email>
+</user>
+
+ +

The XML Reader uses the configured record option to pull out the data for each record - in this case we +set record to 'user', so each <user> above will be converted into a User model.

+ +

Reading other XML formats

+ +

If you already have your XML format defined and it doesn't look quite like what we have above, you can usually +pass XmlReader a couple of configuration options to make it parse your format. For example, we can use the +root configuration to parse data that comes back like this:

+ +
<?xml version="1.0" encoding="UTF-8"?>
+<users>
+    <user>
+        <id>1</id>
+        <name>Ed Spencer</name>
+        <email>ed@sencha.com</email>
+    </user>
+    <user>
+        <id>2</id>
+        <name>Abe Elias</name>
+        <email>abe@sencha.com</email>
+    </user>
+</users>
+
+ +

To parse this we just pass in a root configuration that matches the 'users' above:

+ +
reader: {
+    type  : 'xml',
+    root  : 'users',
+    record: 'user'
+}
+
+ +

Note that XmlReader doesn't care whether your root and record elements are nested deep inside +a larger structure, so a response like this will still work: + +

<?xml version="1.0" encoding="UTF-8"?>
+<deeply>
+    <nested>
+        <xml>
+            <users>
+                <user>
+                    <id>1</id>
+                    <name>Ed Spencer</name>
+                    <email>ed@sencha.com</email>
+                </user>
+                <user>
+                    <id>2</id>
+                    <name>Abe Elias</name>
+                    <email>abe@sencha.com</email>
+                </user>
+            </users>
+        </xml>
+    </nested>
+</deeply>
+
+ +

Response metadata

+ +

The server can return additional data in its response, such as the total number of records +and the success status of the response. These are typically included in the XML response +like this:

+ +
<?xml version="1.0" encoding="UTF-8"?>
+<total>100</total>
+<success>true</success>
+<users>
+    <user>
+        <id>1</id>
+        <name>Ed Spencer</name>
+        <email>ed@sencha.com</email>
+    </user>
+    <user>
+        <id>2</id>
+        <name>Abe Elias</name>
+        <email>abe@sencha.com</email>
+    </user>
+</users>
+
+ +

If these properties are present in the XML response they can be parsed out by the XmlReader and used by the +Store that loaded it. We can set up the names of these properties by specifying a final pair of configuration +options:

+ +
reader: {
+    type: 'xml',
+    root: 'users',
+    totalProperty  : 'total',
+    successProperty: 'success'
+}
+
+ +

These final options are not necessary to make the Reader work, but can be useful when the server needs to report +an error or if it needs to indicate that there is a lot of data available of which only a subset is currently being +returned.

+ +

Response format

+ +

Note: in order for the browser to parse a returned XML document, the Content-Type header in the HTTP +response must be set to "text/xml" or "application/xml". This is very important - the XmlReader will not +work correctly otherwise.

+ +
Defined By

Config Options

Other Configs

 
Name of the property within a row object +that contains a record identifier value. Defaults to The id of the model. +I...

Name of the property within a row object +that contains a record identifier value. Defaults to The id of the model. +If an idProperty is explicitly specified it will override that of the one specified +on the model

+
 
True to automatically parse models nested within other models in a response +object. See the Ext.data.reader.Reader in...

True to automatically parse models nested within other models in a response +object. See the Ext.data.reader.Reader intro docs for full explanation. Defaults to true.

+
 

The name of the property which contains a response message. +This property is optional.

+

The name of the property which contains a response message. +This property is optional.

+
 

The DomQuery path to the repeated element which contains record information.

+

The DomQuery path to the repeated element which contains record information.

+
 
Required. The name of the property +which contains the Array of row objects. Defaults to undefined. +An exception wil...

Required. The name of the property +which contains the Array of row objects. Defaults to undefined. +An exception will be thrown if the root property is undefined. The data +packet value for this property should be an empty array to clear the data +or show no data.

+
 
Name of the property from which to +retrieve the success attribute. Defaults to success. See +Ext.data.proxy.Proxy.exc...

Name of the property from which to +retrieve the success attribute. Defaults to success. See +Ext.data.proxy.Proxy.exception +for additional information.

+
 
Name of the property from which to +retrieve the total number of records in the dataset. This is only needed +if the wh...

Name of the property from which to +retrieve the total number of records in the dataset. This is only needed +if the whole dataset is not passed in one go, but is being paged from +the remote server. Defaults to total.

+
Defined By

Properties

 

The raw data object that was last passed to readRecords. Stored for further processing if needed

+

The raw data object that was last passed to readRecords. Stored for further processing if needed

+
 

DEPRECATED - will be removed in Ext JS 5.0. This is just a copy of this.rawData - use that instead

+

DEPRECATED - will be removed in Ext JS 5.0. This is just a copy of this.rawData - use that instead

+
Defined By

Methods

 
Xml( +Object config) + : void

 

+

Parameters

  • config : Object

    Optional config object

    +

Returns

  • void    +
 
getData( +Object data) + : Object

Normalizes the data object

+

Normalizes the data object

+

Parameters

  • data : Object

    The raw data object

    +

Returns

  • Object   

    Returns the documentElement property of the data object if present, or the same object if not

    +
 
Takes a raw response object (as passed to this.read) and returns the useful data segment of it. This must be implemen...

Takes a raw response object (as passed to this.read) and returns the useful data segment of it. This must be implemented by each subclass

+

Parameters

  • response : Object

    The responce object

    +

Returns

  • Object   

    The useful data from the response

    +
 
read( +Object response) + : Ext.data.ResultSet
Reads the given response object. This method normalizes the different types of response object that may be passed +to ...

Reads the given response object. This method normalizes the different types of response object that may be passed +to it, before handing off the reading of records to the readRecords function.

+

Parameters

  • response : Object

    The response object. This may be either an XMLHttpRequest object or a plain JS object

    +

Returns

  • Ext.data.ResultSet   

    The parsed ResultSet object

    +
 
readRecords( +Object doc) + : Ext.data.ResultSet

Parses an XML document and returns a ResultSet containing the model instances

+

Parses an XML document and returns a ResultSet containing the model instances

+

Parameters

  • doc : Object

    Parsed XML document

    +

Returns

  • Ext.data.ResultSet   

    The parsed result set

    +
\ No newline at end of file