1. #1
    Ext User
    Join Date
    Nov 2010
    Posts
    3
    Vote Rating
    0
    jmuchrisf is on a distinguished road

      0  

    Default 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:
    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>
    maps 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'
    ])
    I have something like:
    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>
    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.

  2. #2
    Sencha - Community Support Team Condor's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    24,246
    Answers
    1
    Vote Rating
    95
    Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of

      0  

    Default


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

  3. #3
    Ext User
    Join Date
    Nov 2010
    Posts
    3
    Vote Rating
    0
    jmuchrisf is on a distinguished road

      0  

    Default


    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.

  4. #4
    Sencha - Community Support Team Condor's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    24,246
    Answers
    1
    Vote Rating
    95
    Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of

      0  

    Default


    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;
            }
        }]
    });

  5. #5
    Sencha User
    Join Date
    Nov 2011
    Posts
    2
    Vote Rating
    0
    Alexx2011 is on a distinguished road

      0  

    Thumbs up


    Hi, i have the similar problem. My XML file is:
    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>
    I have created store and nested XML readers:
    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',{})
                  }
    });
    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:
    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
                    }, 
                       ..........
    });
    How to show values? (Actually, I want to show parameters for chosen lake only)

  6. #6
    Sencha User
    Join Date
    Nov 2011
    Posts
    2
    Vote Rating
    0
    Alexx2011 is on a distinguished road

      0  

    Default


    Additionally,
    When my model is:
    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'}
    	]	
    });
    I can see values of llr parameters, but still just one row (it should be several)

  7. #7
    Sencha User
    Join Date
    Nov 2010
    Posts
    2
    Vote Rating
    0
    anand.kochar is on a distinguished road

      0  

    Default 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'},

    ])
    });

  8. #8
    Sencha User
    Join Date
    Jan 2013
    Location
    Germany, Freiburg i. Br.
    Posts
    31
    Answers
    4
    Vote Rating
    8
    StudentDaniel will become famous soon enough

      0  

    Default 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

    <person sex="female">
    <firstname>Anna</firstname>
    <lastname>Smith</lastname>
    </person>
    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"...


    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

  1. [FIXED-583] nested xml / complex xml, cant get associations to work
    By Nostromo in forum Sencha Touch 1.x: Bugs
    Replies: 18
    Last Post: 20 Mar 2012, 2:12 PM
  2. XMLReader and Grids; read and xml string and populate grid
    By brayan in forum Ext 1.x: Help & Discussion
    Replies: 2
    Last Post: 4 May 2009, 11:46 AM
  3. Replies: 9
    Last Post: 20 Aug 2008, 8:16 PM
  4. Populate grid from Inline XML (XmlReader)
    By joji_khan in forum Community Discussion
    Replies: 1
    Last Post: 28 Apr 2008, 12:47 PM

Thread Participants: 4