PDA

View Full Version : How to read the attributes from an xml file and display them



nash99
18 Jun 2009, 7:17 AM
Hi ,
I need to parse through the xml file (test.xml) and display the values of the attributes in the jsp file.

I am doing the following in test1.jsp file to retrieve the attributes from the test.xml file:


//data store

var ds = new Ext.data.Store({
// load using HTTP
proxy: new Ext.data.HttpProxy({url: '../xml/test.xml'}),
// the return will be XML, so lets set up a reader
reader: new Ext.data.XmlReader({
// records will have an "Item" tag
record: 'chart' ,
id: 'id'
}, [{name: 'bgcolor', mapping:'@bgcolor'}])
});


//this is the on function

ds.on('load', function(ds, records, options) {

alert("COUNT***" +ds1.getCount());
alert("GETAT***"+ds1.getAt(0));

);

});

//this is the init function of the jsp

var Portal = function() {
return {
init:function () {
var loadMask = new Ext.LoadMask(document.body);loadMask.show();

ds.load(); // loading the dataset
var test = ds.getAt(0); // getting the value at zero


alert("<<<<>>>>" +test);
alert("check count" +ds.getCount());
....
}
}
}


// this is the xml file

<?xml version="1.0" encoding="UTF-8"?>
<chart origW='300' origH='300' autoScale='1' bgcolor='FFFFFF'>
<annotations>
<annotationGroup id='Caption'>
<annotation type='text' borderColor='FFFFFF' fontSize='12' bold='1' x='160'y='4'label='label' />
</annotationGroup>
</annotations>
</chart>


---- The alert() shows the count as 0----
can any body help me on this issue (to display the xml attribute)
or provide an example on how to parse the xml and display the attibute values(its ok If I can alert the values).
I am new to ext-js


Thanks
Nash

Condor
18 Jun 2009, 7:21 AM
You can't use the 'chart' element as the 'record', because it isn't contained in another element.

nash99
18 Jun 2009, 7:53 PM
I changed ,
it to the other node(inner node) but it still has a problem accessing the
attributes of the node.
Can anyone provide an example related to this problem.

Condor
18 Jun 2009, 11:38 PM
You have 2 alerts:
1. In the load eventhandler.
If the load succeeds this will be called and should have count=1. You should also add a loadexception handler in case the load fails.
2. Directly after the call to load().
Since load is asynchronous these will always return 0. load() only sends a request to the server. You have to wait for the response before you can query the number of records (using the load eventhandler or the load() callback).