View Full Version : XML mapping for attribute always returns empty

27 Mar 2012, 4:15 PM
I'm stuck - really ;-)

So xml is as follows :

<product id="1040" sequence="1">
<name>Priority Courier</name>
<product id="1030" sequence="2">
<product id="1020" sequence="3">

and model is defined like this :

Ext.define('MyStore.model.ShippingOption', {
extend: 'Ext.data.Model',

fields: [
'name', 'rate', 'shippingDate',
{ name: 'shipcode', mapping: 'product/@id' }

and store is :

Ext.define('MyStore.store.ShippingOptions', {
extend: 'Ext.data.Store',

model: 'MyStore.model.ShippingOption',
autoLoad: false,

proxy: {
type: 'ajax',
url: '/api/CanadaPostRates.php',
reader: {
type: 'xml',
root: 'eparcel',
record: 'product'

I can get all my record info perfectly into the store - however attribute 'id' for <product id=??>
is blank when I reference record.data.shipcode. All other info is fine though.

Any ideas ?



28 Mar 2012, 8:18 AM
Found the answer - apparently you can map using the following to access the attribute in the record node itself.

{ name: 'shipcode', mapping: '@id' }

PS - this unfortunately doesn't help in obtaining attributes embedded in child nodes of the record - only the root node. Not sure how I could do that.