PDA

View Full Version : XMLReader -> Attribute Mapping -> Ext.DomQuery?



Aigu
15 Nov 2010, 4:41 PM
Hi

I need to read some attributes out of an XML.
I tried several ways to get the mapping to an attribute, but didn't manage to get it working.
I ended up doing a hack which didn't work on older android devices.

XML

<a>
<b c="howto">no problem to get this text</b>
<b c="bla">foo bar</b>
</a>

XmlReader

record: "b",
totalProperty: false,
model: 'foo'

Mappings i tried

mapping: 'c'
mapping: 'b[c]'
mapping: '[c]'
mapping: 'b[@c]'
mapping: '[@c]'
mapping: '[name=c]'
mapping: '@c'

Unfortunately, non of them worked.
Does anyone has an idea? I can't change the format of the XML.

Hack on store callback which did not work on all devices i tested on:

for (var i = 0; i < records.length; i++){
records[i].data.c= records[i].raw.attributes.getNamedItem('c').nodeValue;
};

Thx
Fredi

Aigu
18 Nov 2010, 1:57 PM
If somebody has the same issue:
http://www.sencha.com/forum/showthread.php?109450-problem-with-attribute-mapping-in-xml-reader&highlight=xml+attribute
I don't think it's the right way because in the mapping doc of Ext.data.Field its written:


Ext.data.XmlReader
The mapping is an Ext.DomQuery path to the data item relative to the DOM element that represents the record. Defaults to the field name.

But anyway.... this solved my problem.

Arnom Maciel
23 Aug 2011, 1:24 PM
Hello, please help me. I need to read the attribute "url" tag in the "enclosure" as trex xml below. Demonstrate the code I'm using, but do not know how to access the attribute.

The XML:
<item>
<title>::Palavra 21-08-2011</title>
<description>Domingo-21-08</description>
<enclosure url="http://download.com.br/podcast/bm/21082011.mp3" length="29896704" type="mp3" />
<pubDate>Sun 21 Aug 2011 21:00:00 -0300</pubDate>
</item>
The Code:
Ext.regModel('PAM', {
fields: ['title', 'description', 'enclosure','pubDate']
});
var pam = new Ext.data.Store({
model: 'PAM',
autoLoad:true,
proxy: {
type: 'ajax',
url : 'pam.xml',
reader: {
type : 'xml',
root : 'channel',
record: 'item'
}
}
});

Who can help, thank you.