Reading XML in id = "key" value = "value" format?

How can I read XML in attribute format in ExtJS repository, where key / values ​​are listed on the same line as id / value? I am more familiar with the second format 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>

A 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>
+4
source share
1 answer

This is not well documented, but matching for your fields can be any expression accepted by Ext.dom.Query . Therefore, when you usually have a simple β€œtitle” mapping 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 the β€œcolumn” tags, whose identification attributes correspond to the name of the field you are looking for, so in your model or repository you can define your fields as follows:

fields: [ { name: 'title', mapping: 'column[id=title]@value' }, { name: 'director', mapping: 'column[id=director]@value' }, { name: 'year', mapping: 'column[id=year]@value' } ], 
+3
source

All Articles