Properties Methods Events Config Options Direct Link

    DataReader
      XmlReader

# Class Ext.data.XmlReader

Package: | Ext.data
Defined In: | XmlReader.js
Class: | XmlReader
Extends: | DataReader

Data reader class to create an Array of Ext.data.Record objects from an XML document based on mappings in a provided Ext.data.Record constructor.

Note that 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".

Example code:

    var Employee = Ext.data.Record.create([
       {name: 'name', mapping: 'name'},     // "mapping" property not needed if it's the same as "name"
       {name: 'occupation'}                 // This field will use "occupation" as the mapping.
    ]);
    var myReader = new Ext.data.XmlReader({
       totalRecords: "results", // The element which contains the total dataset size (optional)
       record: "row",           // The repeated element which contains row information
       id: "id"                 // The element within the row that provides an ID for the record (optional)
    }, Employee);

This would consume an XML file like this:

    <?xml?>
    <dataset>
     <results>2</results>
     <row>
       <id>1</id>
       <name>Bill</name>
       <occupation>Gardener</occupation>
     </row>
     <row>
       <id>2</id>
       <name>Ben</name>
       <occupation>Horticulturalist</occupation>
     </row>
    </dataset>

## Config Options

Config Options | Defined By
--- | ---
| id : String The DomQuery path relative from the record element to the element that contains a record identifier value. | XmlReader
| record : String The DomQuery path to the repeated element which contains record information. | XmlReader
| success : String The DomQuery path to the success attribute used by forms. | XmlReader
| totalRecords : String The DomQuery path from which to retrieve the total number of records in the dataset. This is only needed if the whole... The DomQuery path 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. | XmlReader

## Public Properties

Property | Defined By
--- | ---
| meta : Mixed This DataReader's configured metadata as passed to the constructor. | DataReader
| xmlData : XMLDocument After any data loads/reads, the raw XML Document is available for further custom processing. | XmlReader

## Public Methods

Method | Defined By
--- | ---
| XmlReader( `Object meta`, `Object recordType` ) Create a new XmlReader. Create a new XmlReader. Parameters: `meta` : Object Metadata configuration options `recordType` : Object Either an Array of field definition objects as passed to Ext.data.Record.create, or a Record constructor object created using Ext.data.Record.create. Returns: `` | XmlReader
| read( `Object response` ) : Object This method is only used by a DataProxy which has retrieved data from a remote server. This method is only used by a DataProxy which has retrieved data from a remote server. Parameters: `response` : Object The XHR object which contains the parsed XML document. The response is expected to contain a property called `responseXML` which refers to an XML document object. Returns: `Object` records A data block which is used by an {@link Ext.data.Store} as a cache of Ext.data.Records. | XmlReader
| readRecords( `Object doc` ) : Object Create a data block containing Ext.data.Records from an XML document. Create a data block containing Ext.data.Records from an XML document. Parameters: `doc` : Object A parsed XML document. Returns: `Object` records A data block which is used by an {@link Ext.data.Store} as a cache of Ext.data.Records. | XmlReader

## Public Events

This class has no public events.