PDA

View Full Version : Parse XML



westvovik
9 Mar 2010, 9:38 AM
Please help me to solve the given problem
I wish to parse this lines



<list type="metro" cityName="Moscow" cityId="12918">
<row metroId="1" metroName="aviomotornia"/>
<row metroId="2" metroName="avtozavodskay"/>
</list>I tried the given code



store: new Ext.data.Store({
url: 'xml/metro.xml',
autoLoad: true, // required for the combo that does not use Ajax
reader: new Ext.data.XmlReader(
{ record: 'row', id: 'metroId'},
[{
name: 'metroId',
name: 'metroName'
}]
)
})but it does not work, please help the programmer from Russia, in advance Thanks

fay
9 Mar 2010, 10:51 AM
When you're referring to an attribute of the node, use '@'

Try:


store: new Ext.data.Store({
url: 'xml/metro.xml',
autoLoad: true, // required for the combo that does not use Ajax
reader: new Ext.data.XmlReader({
record: 'row',
idProperty: '@metroId'
},
[
{name: 'metroId', mapping: '@metroId'},
{name: 'metroName', mapping: '@metroName'}
]
)
})

Elijah
9 Mar 2010, 11:07 AM
I would also make sure that you do not have any whitespace in the xml that you are getting back from the server. Some times there are issues when whitespace appears in the front of the xml so


<list type="metro" cityName="Moscow" cityId="12918">
<row metroId="1" metroName="aviomotornia"/>
<row metroId="2" metroName="avtozavodskay"/>
</list>is not the same as

<list type="metro" cityName="Moscow" cityId="12918">
<row metroId="1" metroName="aviomotornia"/>
<row metroId="2" metroName="avtozavodskay"/>
</list>

westvovik
9 Mar 2010, 11:48 AM
fieldLabel: 'Metro',
name: 'metro',
xtype: 'combo',
typeAhead: true,
mode: 'local',
emptyText:'Metro do not select',
selectOnFocus:true,
displayField: 'metro',
store: new Ext.data.Store({
url: 'xml/metro.xml',
autoLoad: true, // required for the combo that does not use Ajax
reader: new Ext.data.XmlReader({
record: 'row',
idProperty: '@metroId'},
[
{name: 'metroId', mapping: '@metroId'},
{name: 'metroName', mapping: '@metroName'}
]
})

So here a full code of my element
After element loading, by pressing a combo boxing I see only empty elements without any names that then does not work,
And not what blanks are not present before xml, it is visible that elements were loaded, but probably displayed not truly

fay
9 Mar 2010, 11:55 AM
displayField: 'metro',

change to


displayField: 'metroName',