-
2 Dec 2010 7:13 PM #1
Unanswered: XMLReader, complex xml for grid
Unanswered: XMLReader, complex xml for grid
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:
maps like:Code:<Item> <ASIN>0446355453</ASIN> − <DetailPageURL> http://www.amazon.com/gp/redirect.html%3FASIN=0446355453%26tag=ws%26lcode=xm2%26cID=2025%26ccmID=165953%26location=/o/ASIN/0446355453%253FSubscriptionId=1A7XKHR5BYD0WPJVQEG2 </DetailPageURL> − <ItemAttributes> <Author>Sidney Sheldon</Author> <Manufacturer>Warner Books</Manufacturer> <ProductGroup>Book</ProductGroup> <Title>Master of the Game</Title> </ItemAttributes> </Item>
I have something like:Code: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'}, 'Title', 'Manufacturer', 'ProductGroup', // Detail URL is not part of the column model of the grid 'DetailPageURL' ])
That should get me going where I need to go. In Jquery, it's would map like this:Code:<buildings> <building> <floor name="firstfloor" display="First Floor"> <field_name name="sqfootage" display="100 sq ft"/> <field_name name="height" display="9ft"/> </floor> <floor name="basement" display="Sub Zero Floor"> <field_name name="sqfootage" display="200 sq ft"/> <field_name name="height" display="12ft"/> </floor> </building </buildings>
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 #2Sencha - Community Support Team
- Join Date
- Mar 2007
- Location
- The Netherlands
- Posts
- 24,251
- Vote Rating
- 40
- Answers
- 1
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 #3
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 #4Sencha - Community Support Team
- Join Date
- Mar 2007
- Location
- The Netherlands
- Posts
- 24,251
- Vote Rating
- 40
- Answers
- 1
You could use nested readers, e.g.
Code: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 #5
Hi, i have the similar problem. My XML file is:
I have created store and nested XML readers:Code:<?xml version="1.0" encoding="UTF-8"?> <lakes> <lake> <lakeId>Lake1</lakeId> <llrParameters LN="1167" LP="58" TotN="936" TotP="31" Q="7"></llrParameters> <llrParameters LN="1310" LP="69" TotN="1006" TotP="41" Q="6"></llrParameters> ............. </lake> <lake> <lakeId>Lake2</lakeId> <llrParameters LN="1250" LP="55" TotN="999" TotP="35" Q="8"></llrParameters> ............. </lake> </lakes>
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).Code:Ext4.define('llrParametersXmlReader',{ 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'} ] }); Ext4.define('lakeXmlReader',{ 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',{}) } });
The grid is like:
How to show values? (Actually, I want to show parameters for chosen lake only)Code:var resultsStore = Ext4.create('LlrParametersStore',{}); var grid = Ext4.create('Ext4.grid.Panel', { store: resultsStore, selType: 'rowmodel', frame: true, autoScroll: true, columns:[ { header: "LN", dataIndex: "LN", width: 130 }, .......... });
-
15 Nov 2011 1:09 AM #6
Additionally,
When my model is:
I can see values of llr parameters, but still just one row (it should be several)Code: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'} ] });
-
30 Nov 2011 12:03 AM #7
Not able to map XML to XML Store
Not able to map XML to XML Store
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 :
<?xml version="1.0" encoding="utf-8" ?>
<OpCh>
- <quot>
<p key="datax">valuex</p>
<p key="datay">valuey</p>
</quot>
- <op>
<p key="data1">value11</p>
<p key="data2">value12</p>
</op>
- <op>
<p key="data1">value21</p>
<p key="data2">value22</p>
</op>
<count>2</count>
<aKey>123</AccessKey>
</OpCh>
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 #8
Thread endet ?
Thread endet ?
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 ?
http://www.w3schools.com/xml/xml_attributes.asp
A need to do read/write XML within Attributs and Elements.<person sex="female">
<firstname>Anna</firstname>
<lastname>Smith</lastname>
</person>
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"...
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... :-)
Similar Threads
-
[FIXED-583] nested xml / complex xml, cant get associations to work
By Nostromo in forum Sencha Touch 1.x: BugsReplies: 18Last Post: 20 Mar 2012, 2:12 PM -
XMLReader and Grids; read and xml string and populate grid
By brayan in forum Ext 1.x: Help & DiscussionReplies: 2Last Post: 4 May 2009, 11:46 AM -
Improve performance: filtering some rows in grid from a xml file via xmlreader
By luckyxx in forum Ext 2.x: Help & DiscussionReplies: 9Last Post: 20 Aug 2008, 8:16 PM -
Populate grid from Inline XML (XmlReader)
By joji_khan in forum Community DiscussionReplies: 1Last Post: 28 Apr 2008, 12:47 PM


Reply With Quote