PDA

View Full Version : Get the same xml element name's attribute value



may_215
26 Jun 2013, 7:07 AM
I am creating grid with the folowing xml:
<NODES>
<ENTRY MODIFIED_DATE="2013/4/14" TITLE="A3" ARTIST="Subb">
<LOCATION DIR=""/>
<INFO BITRATE="1411200" KEY=""/>
<TEMPO BPM="132" />
<CV NAME="0" />
<CV NAME="1" />
<CV NAME="2" />
<CV NAME="3" />
<CV NAME="4" />
</ENTRY>
<ENTRY MODIFIED_DATE="2013/4/14" TITLE="A3" ARTIST="Subb">
<LOCATION DIR=""/>
<INFO BITRATE="1411200" KEY=""/>
<TEMPO BPM="132" />
<CV NAME="0" />
<CV NAME="5" />
<CV NAME="6" />
<CV NAME="7" />
<CV NAME="8" />
</ENTRY>
</NODES>


The column mapping:


{name: 'TITLE', mapping: '@TITLE'},
{name: 'ARTIST', mapping: '@ARTIST'},
{name: 'FILE', mapping: 'LOCATION > @DIR'},
{name: 'MODIFIED_DATE', mapping: '@MODIFIED_DATE'},
{name: 'BITRATE', mapping: 'INFO > @BITRATE'},
{name: 'KEY', mapping: 'INFO > @KEY'},
{name: 'BPM', mapping: 'TEMPO > @BPM'},
{name: 'CV_1', mapping: 'CV > @NAME'},
{name: 'CV_2', mapping: 'CV > @NAME'},
{name: 'CV_3', mapping: 'CV > @NAME'},
{name: 'CV_4', mapping: 'CV > @NAME'},
{name: 'CV_5', mapping: 'CV > @NAME'}


And the problem is the CV_* columns get the first attribute value, e.g. 0.
How do I need to map in order to get each element's attribute value (e.g. CV_1=0, CV_2=1 etc..)?
Do I need to set index?


thx.

slemmon
28 Jun 2013, 12:44 PM
See if the selector syntax in the below example is what you're looking for:



Ext.create('Ext.data.Store', {
storeId:'simpsonsStore',
fields:[{
name: 'CV_1',
mapping: 'CV@NAME'
}, {
name: 'CV_2',
mapping: 'CV + CV@NAME'
}, {
name: 'CV_3',
mapping: 'CV + CV + CV@NAME'
}],
autoLoad: true,
proxy: {
type: 'ajax',
url: 'data/xml.xml',
reader: {
type: 'xml',
root: 'NODES',
record: 'ENTRY'
}
}
});


Ext.create('Ext.grid.Panel', {
title: 'Simpsons',
store: Ext.data.StoreManager.lookup('simpsonsStore'),
columns: [
{ text: 'CV_1', dataIndex: 'CV_1', flex: 1},
{ text: 'CV_2', dataIndex: 'CV_2', flex: 1},
{ text: 'CV_3', dataIndex: 'CV_3', flex: 1}
],
height: 200,
width: 400,
renderTo: Ext.getBody()
});