PDA

View Full Version : How to read the attributes of the root node of an xml file



nash99
18 Jun 2009, 11:43 PM
Hi all ,

I am trying to access the attributes of the root node of the xml file (test.xml).
I was able to access all the inner nodes (attributes) of the xml file .
Can any body provide e an example on how to access the attributes of the root node of xml file.

Description : test.xml

<?xml version="1.0" encoding="UTF-8"?>
<ItemSearchResponse value3="ReqVal">
<OperationRequest value2="@@ReqVal">
<HTTPHeaders>
<Header Name="UserAgent"
Value="Mozilla/4.0"></Header>
</HTTPHeaders>
</OperationRequest>
</ItemSearchResponse>

I need to access value3 from the root node of the xml (and just alert it), I am using dataStore to retrieve the inner attributes.
Please help me
thanks
Nash

Animal
18 Jun 2009, 11:55 PM
http://extjs.com/deploy/ext-3.0-rc2/docs/?class=Ext.data.XmlReader&member=xmlData

nash99
19 Jun 2009, 1:06 AM
Hi,
Thanks for the response ..
I tried using the xmlReader and tried to access the value3 . but I could not ..

Ext.onReady(function(){

// create the Data Store
var store = new Ext.data.Store({
// load using HTTP
url: 'test.xml',

// the return will be XML, so lets set up a reader
reader: new Ext.data.XmlReader({

record: 'ItemSearchResponse '

}, [
// set up the fields mapping into the xml doc
// The first needs mapping, the others are very basic
{name: 'value3', mapping: '@value3'}
])
});

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

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

});


I am able to get the attribute values of the inner nodes but not the root node.
I am pretty new to extjs , kindly provide me any example (if present).
Any help is greatly appreciated.

Thanks
Nash

Animal
19 Jun 2009, 1:09 AM
Are you reading a list of repeated record items here?

nash99
19 Jun 2009, 1:18 AM
No ,
I am not reading a list of repeated record items.
I am just trying to read the attribute(value3) present inside the ItemSearchResponse (this is the root node).
I should be able to just alert the "value3".


<?xml version="1.0" encoding="UTF-8"?>
<ItemSearchResponse value3="ReqVal">
</ItemSearchRespons>

Animal
19 Jun 2009, 1:46 AM
Just do an Ext.Ajax.request then, and process the responseXML.

nash99
19 Jun 2009, 1:55 AM
Thanks for the reply ,
I have no idea How to do the
Ext.Ajax.request , and process the responseXML.
Can you please provide me an example or a way to do this process.
I need to do it ASAP.
I really appreciate all your help


Nash

Animal
19 Jun 2009, 2:35 AM
http://extjs.com/deploy/ext-3.0-rc2/docs/?class=Ext.Ajax&member=request

And the response object should be very familiar to you as a professional web developer. It's an XMLHttpRequest (or simulacrum thereof).