is it possible to parse data from an xml containing similar tags?
My xml file is:
<?xml version="1.0" encoding="UTF-8" ?>
<root>
<investors>
<investor>Active</investor>
<investor>Aggressive</investor>
<investor>Conservative</investor>
<investor>Day Trader</investor>
<investor>Very Active</in开发者_运维问答vestor>
</investors>
<events>
<event>3 Month Expiry</event>
<event>LEAPS</event>
<event>Monthlies</event>
<event>Monthly Expiries</event>
<event>Weeklies</event>
<event>Weeklies Expiry</event>
</events>
<prices>
<price>0.05</price>
<price>0.5</price>
<price>1</price>
<price>1</price>
<price>22</price>
<price>100.34</price>
</prices>
</root>
my ExtJS code is :
Ext.regModel('Card', {
fields: ['investor','event','price']
});
var store = new Ext.data.Store({
model: 'Card',
proxy: {
type: 'ajax',
url: 'http:/.../initpicker.php',
reader: {
type: 'xml',
record: 'root'
}
},
listeners: {
single: true,
datachanged: function(){
var items = [];
store.each(function(r){
stocks.push({text: '<span style="color:Blue;font-weight:bolder;font-size:30px;">'+ r.get('price') +'</span>'});
values.push({text: '<span style="font-weight: bold;font-size:25px;">'+ r.get('investor') +'</span>'});
points.push({text: '<span style="font-weight: bold;font-size:25px;">'+ r.get('event') +'</span>'});
});
}
}
});
store.read();
my question is that if my xml contains same tags like for five times can we still parse the data. . . . .?
i've tried this code but it only parsed the first one..........................
if there is anyother way please suggest. . .
Thank you.
It really depends on what your Record looks like.
Is the first investor element supposed to be related to the first event and price elements and bundled into a single Record? What about the second record - would that contain Aggressive, LEAPS and 0.5 as data values? If so, the XML doesn't really make that much sense.
I don't believe Sencha's XmlReader will cope with this that well, which would explain why you're only getting the first record.
There are two solutions:
- Modify the XML being produced to make more sense to the XmlReader
- Write your own Reader class to parse and extract records from the format of data available to you
you can parse the xml using ExtJs. But xml file should be in same domain
What are you using this XML for?
I'm assuming it's for a grid. Also your code doesn't seem to match the tags in your XML. What data are you trying to grab in your code? You should be accessing data from the tags in the XML when you set up the data object.
I would suggest that you rethink the structure of your XML. Your tags do not describe the data contained within the tags. In some ways, you seem to be missing the point of XML.
Something like this should be what you need to populate a grid.
<investors>
<investor>
<name>Bob</name>
<style>Aggressive</style>
<price>0.5</price>
</investor>
<investor>
<name>Francis</name>
<price>150.00</price>
</investor>
</investors>
I highly suggest you check out this link: XML Grid Sample from Sencha Webste
精彩评论