PDA

View Full Version : mapping xml to combo when record has no inner tags



extjsbrenda
23 Jul 2009, 8:13 AM
I'm using an xml file to populate a combobox.

I'm confused about how to do this because my xml record element has no inner elements.

Here's my xml:


<?xml version="1.0" encoding="UTF-8"?>
<ITEMLIST>
<ITEM>CAT</ITEM>
<ITEM>DOG</ITEM>
<ITEM>TURTLE</ITEM>
</ITEMLIST>
How do I configure the store's XMLReader to use the <ITEM> tag as both the record and
the display value?


Thank you

extjsbrenda
26 Jul 2009, 7:46 AM
wow. no replies. is what i'm asking not possible to do?

mjlecomte
26 Jul 2009, 8:04 AM
wow. no replies. is what i'm asking not possible to do?

that or maybe you'd have better luck posting some code you've tried.

http://extjs.com/learn/Ext_Forum_Help#Posting_a_working_showcase

extjsbrenda
27 Jul 2009, 7:22 AM
The following combo box code works with the following xml.


var Recs = new Ext.data.Record.create([{name:'TYPE'}]);

var TypeStore = new Ext.data.Store({
id: 0,
fields: ['TYPE'],
url: 'sample2.xml',
// autoLoad: true,
reader: new Ext.data.XmlReader(
{record: 'ITEM'}, Recs),

});
.
.
.
{
xtype: 'combo',
name: 'txt-test4',
fieldLabel: 'Type',
id:'type-combo',
displayField:'TYPE',
valueField: 'TYPE',
emptyText:'Select Type',
mode:'local',
store: TypeStore,
editable:false,
},

xml -
<?xml version="1.0" encoding="UTF-8"?>
<ITEMLIST>
<ITEM><TYPE>CAT</TYPE></ITEM>
<ITEM><TYPE>DOG</TYPE></ITEM>
<ITEM><TYPE>TURTLE</TYPE></ITEM>
</ITEMLIST>
The problem is, that the xml file that I have doesn't have the '<TYPE>' tags.

xml with no <type> tags:


<?xml version="1.0" encoding="UTF-8"?>
<ITEMLIST>
<ITEM>CAT</ITEM>
<ITEM>DOG</ITEM>
<ITEM>TURTLE</ITEM>
</ITEMLIST>
How do I adjust the above reader and store to work when there's no inner '<type>' tag ?
Every adjustment I've made results in blank combo menu values.


Thank you :)

Brenda

Condor
27 Jul 2009, 7:38 AM
var ItemRecord = new Ext.data.Record.create([
{name: 'TYPE', mapping: '/'}
]);

var TypeStore = new Ext.data.Store({
url: 'sample2.xml',
reader: new Ext.data.XmlReader({
id: '/',
record: 'ITEM'
}, ItemRecord)
});

extjsbrenda
27 Jul 2009, 9:05 AM
Thanks Condor -

This is exactly what I was looking for. Just for the record (and future readers),
Where your code says 'TYPE' replace with 'ITEM'.

Thanks again for your help,
Brenda