View Full Version : XMLReader, complex xml for grid

2 Dec 2010, 7:13 PM
Good evening everyone!

All of the example EXTJs XML/grid examples use the Books, ISBN, ASIN number example. I have some XML that's a little more complex, and I don't know how to map these items to the grid fields. Any advice?

Examples I see:





<Author>Sidney Sheldon</Author>
<Manufacturer>Warner Books</Manufacturer>
<Title>Master of the Game</Title>
maps like:

reader: new Ext.data.XmlReader({
// records will have an "Item" tag
record: 'Item',
id: 'ASIN',
totalRecords: '@total'
}, [
// set up the fields mapping into the xml doc
// The first needs mapping, the others are very basic
{name: 'Author', mapping: 'ItemAttributes > Author'},
// Detail URL is not part of the column model of the grid

I have something like:

<floor name="firstfloor" display="First Floor">
<field_name name="sqfootage" display="100 sq ft"/>
<field_name name="height" display="9ft"/>
<floor name="basement" display="Sub Zero Floor">
<field_name name="sqfootage" display="200 sq ft"/>
<field_name name="height" display="12ft"/>


That should get me going where I need to go. In Jquery, it's would map like this:
building.find('building") for each building..
then to get the first floor data it would be something like:
floor.find('floor[name="firstfloor"]').find('field_name[name="height"]').text() or somethingl ike that, to get the height of each floor..

how would I accomplish that in an XMLReader, to get a row for each 'building', and an attribute in each row that maps to the 'firstfloor' height attribute... and it has to be by 'value' of the 'name' attribute, not an index.

and I don't know how to map it.

3 Dec 2010, 3:33 AM
Firstly, what should your store contain? Should it contain buildings (with a 'floors' field) or floors (optionally extended with data from building)?

3 Dec 2010, 7:00 AM
Condor -
thanks for the response. While I see the difference in your two examples, I think the challenge is the same. the way I think about it is buildings with floors, and I only want information on certain floors.... yeah, that's right. I want a list of building supplemented with floor information (almost denormalized, etc)... I'm thinking of putting an XSLT in the middle of my program output and the extjs, but if extjs can do more complex (jquery DOM selector like) querying of XML, that would be great.

and the original XML I have is an industry standard format, so I can't change that.

3 Dec 2010, 7:47 AM
You could use nested readers, e.g.

var floorReader = new Ext.data.XmlReader({
record: 'floor',
fiels: [{
name: 'name',
mapping: '@name'
name: 'display',
mapping: '@display'
name: 'sqfootage',
mapping: 'field_name[name=sqfootage]@display'
name: 'height',
mapping: 'field_name[name=height]@display'
var buildingReader = new Ext.data.XmlReader({
record: 'building',
fields: [{
name: 'floors',
convert: function(v, n){
return floorReader.readRecords(n).records;

15 Nov 2011, 12:27 AM
Hi, i have the similar problem. My XML file is:

<?xml version="1.0" encoding="UTF-8"?>
<llrParameters LN="1167" LP="58" TotN="936" TotP="31" Q="7"></llrParameters>
<llrParameters LN="1310" LP="69" TotN="1006" TotP="41" Q="6"></llrParameters>
<llrParameters LN="1250" LP="55" TotN="999" TotP="35" Q="8"></llrParameters>

I have created store and nested XML readers:

extend: 'Ext4.data.XmlReader',
root: 'lake',
record: 'llrParameters',
fields: [{name: "LN", type: "float", mapping: '@LN'},
{name: "LP", type: "float", mapping: '@LP'},
{name: "TotN", type: "float", mapping: '@TotN'},
{name: "TotP", type: "float", mapping: '@TotP'},
{name: "Q", type: "float", mapping: '@Q'}
extend: 'Ext4.data.XmlReader',
root: 'lakes',
record: 'lake',
fields: [{name: "lakeId", type: "string"},
{name: 'llrParameters', convert: function(v, n)
return new Ext4.create('llrParametersXmlReader',{}).readRecords(n).records;
//(I'm using Ext4,create because I'm working into sandbox)
//The store is:
Ext4.define('LlrParametersStore', {
extend: 'Ext4.data.Store',
autoLoad: true,
model: 'LlrParametersModel',
proxy: {
type: 'ajax',
url : 'xml/LlrParametersXmlStore.xml',
reader: new Ext4.create('lakeXmlReader',{})

This store is the store for a grid. I expect to see values of llrParameters (LN, LP etc) into the grid, but I have seen just zeros (grid contains 2 row - for "lake1" and "lake2" with zeros instead real values of llrParameters).
The grid is like:

var resultsStore = Ext4.create('LlrParametersStore',{});
var grid = Ext4.create('Ext4.grid.Panel', {
store: resultsStore,
selType: 'rowmodel',
frame: true,
autoScroll: true,
{ header: "LN",
dataIndex: "LN",
width: 130

How to show values? (Actually, I want to show parameters for chosen lake only)

15 Nov 2011, 1:09 AM
When my model is:

Ext4.define('LlrParametersModel', {
extend: 'Ext4.data.Model',
fields: [{name: "lakeId", type: "string"},
{name: "LN", type: "float", mapping: 'llrParameters > @LN'},
{name: "LP", type: "float", mapping: 'llrParameters > @LP'},
{name: "TotN", type: "float", mapping: 'llrParameters > @TotN'},
{name: "TotP", type: "float", mapping: 'llrParameters > @TotP'},
{name: "Q", type: "float", mapping: 'llrParameters > @Q'}

I can see values of llr parameters, but still just one row (it should be several)

30 Nov 2011, 12:03 AM
Hi Condor,

I am trying to bind below xml to XMLstore but not able to do so successfully.
Can you please help me with this.

<?xml version="1.0" encoding="utf-8" ?>
- <quot>
<p key="datax">valuex</p>
<p key="datay">valuey</p>
- <op>
<p key="data1">value11</p>
<p key="data2">value12</p>
- <op>
<p key="data1">value21</p>
<p key="data2">value22</p>

XML Store:
XMLStore = new Ext.data.XmlStore({
// store configs
autoDestroy: true,
storeId: 'myXmlStore',
reader: new Ext.data.XmlReader({
record: 'OpCh',
totalRecords : '@count'
// set up the fields mapping into the xml doc
// The first needs mapping, the others are very basic
{name: 'data1', mapping: 'op > data1'},
{name: 'data2', mapping: 'op > data2'},


11 Jan 2013, 4:45 AM
Hello Condor,

because of there is no new comment for more than a year I want to ask you or another Sencha-Support Agent for a final Answer to this thread.

How can I use the Sencha Architect 2 to WORK with XML ?


<person sex="female">

A need to do read/write XML within Attributs and Elements.

Is there a way working with Stores->Proxys->Reader/Writer within the Architect 2 ?
Maybe you can test if there is a useable way with a short example like above.

Hope you don't have bad information like "sencha dose only work with simple XML without Attributs and Elements"... ~o)

I will also ask a second Question about "wadl" as separated thread.

I am testing Sencha the next 4 Weeks and are planing to buy Sencha Complete.

I hope this Investment will be the right way for a student... :-)