Reputation:
How can I read XML in the attribute format into a ExtJS Store, where key/values are specified on one row as id/value? I'm more familiar with the second format given below.
<?xml version="1.0" encoding="UTF-8"?> <XMLResponse> <data> <row> <column id="title" value="Star Wars"/> <column id="director" value="Lucas"/> <column id="year" value="1977"/> </row> <row> <column id="title" value="Jaws"/> <column id="director" value="Spielberg"/> <column id="year" value="1975"/> </row> </data> </XMLResponse>
The more traditional way of writing XML.
<?xml version="1.0" encoding="UTF-8"?> <XMLResponse> <data> <row> <title>Star Wars</title> <director>Lucas</director> <year>1977</year> </row> <row> <title>Jaws</title> <director>Spielberg</director> <year>1975</year> </row> </data> </XMLResponse>
Upvotes: 5
Views: 2258
Reputation: 13390
It's not very well-documented, but the mappings for your fields can be any expression accepted by Ext.dom.Query. So where you'd normally have a simple mapping of "title" to select a child tag named "title", you can include a more complex selector. In this case, you want to select the "value" attribute of "column" tags whose ID attributes match the field name you're looking for, so in your model or store, you can define your fields like so:
fields: [
{ name: 'title', mapping: 'column[id=title]@value' },
{ name: 'director', mapping: 'column[id=director]@value' },
{ name: 'year', mapping: 'column[id=year]@value' }
],
Upvotes: 4