Print Friendly

Class Ext.data.XmlReader

Package:Ext.data
Class:XmlReader
Extends:Ext.data.DataReader
Defined In:XmlReader.js
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 RecordDef = 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)
}, RecordDef);

This would consume an XML file like this:

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

Properties   -  Methods   -  Events   -  Config Options

Public Properties

Property Defined By
  xmlData : XMLDocument XmlReader
After any data loads/reads, the raw XML Document is available for further custom processing.

Public Methods

Method Defined By
  XmlReaderObject meta, Mixed recordType ) XmlReader
Create a new XmlReader
  readObject response ) : Object XmlReader
This method is only used by a DataProxy which has retrieved data from a remote server.
  readRecordsObject doc ) : Object XmlReader
Create a data block containing Ext.data.Records from an XML document.

Public Events

This class has no public events.

Config Options

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

Property Details

xmlData

public XMLDocument xmlData
After any data loads/reads, the raw XML Document is available for further custom processing.
This property is defined by XmlReader.

Constructor Details

XmlReader

public function XmlReader( Object meta, Mixed recordType )
Create a new XmlReader
Parameters:
  • meta : Object
    Metadata configuration options
  • recordType : Mixed
    The definition of the data record type to produce. This can be either a valid Record subclass created with Ext.data.Record.create, or an array of objects with which to call Ext.data.Record.create. See the Ext.data.Record class for more details.

Method Details

read

public function read( Object response )
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 method called 'responseXML' that returns 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.
This method is defined by XmlReader.

readRecords

public function readRecords( Object doc )
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.
This method is defined by XmlReader.

Config Details

id

id : String
The DomQuery path relative from the record element to the element that contains a record identifier value.
This config option is defined by XmlReader.

record

record : String
The DomQuery path to the repeated element which contains record information.
This config option is defined by XmlReader.

success

success : String
The DomQuery path to the success attribute used by forms.
This config option is defined by XmlReader.

totalRecords

totalRecords : String
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.
This config option is defined by XmlReader.

Ext - Copyright © 2006-2007 Ext JS, LLC
All rights reserved.