PDA

View Full Version : loading XML Data from Webservice instead of static file



AndreasS
23 Jan 2011, 12:17 AM
Hi.

I do currently evaluate Ext JS and cannot manage to change some of the samples to load XML data from something else than a static XML file.

I f.i. modified xml-grid.js in examples/grid to load the XML from a webservice. That does not work at all. Following is my modification: url: 'http://www.sedlmeier-consulting.com/uniJetScripts/MGrqispi.dll?AppName=AjaxSample&PrgName=Sheldon'

This is a webservice which returns XML (Content-Type: text/xml).

Any help and insight regarding that is highly appreciated.

Andreas

===

// create the Data Store
var store = new Ext.data.Store({
// load using HTTP
url: 'http://www.sedlmeier-consulting.com/uniJetScripts/MGrqispi.dll?AppName=AjaxSample&PrgName=Sheldon',
// url: 'sheldon.xml',

// the return will be XML, so lets set up a reader
reader: new Ext.data.XmlReader({
// records will have an "Item" tag
record: 'Item',
id: 'ASIN',
totalRecords: '@total'
}, [
// set up the fields mapping into the xml doc
// The first needs mapping, the others are very basic
{name: 'Author', mapping: 'ItemAttributes > Author'},
'Title', 'Manufacturer', 'ProductGroup'
])
});

valititi
23 Jan 2011, 2:27 AM
Is in the base examples of Ext (ext/examples/grid/xml-grid.html) and this works. I just load it 2 minutes ago...

html file :


... <body> ... <div id="example-grid"></div> </body></html>
js file :


Ext.onReady(function(){
var store = new Ext.data.Store({ url: 'sheldon.xml',
reader: new Ext.data.XmlReader({ record: 'Item', id: 'ASIN', totalRecords: '@total'},
[
{name: 'Author', mapping: 'ItemAttributes > Author'},
'Title', 'Manufacturer', 'ProductGroup'
]
)
});

var grid = new Ext.grid.GridPanel({ store: store,
columns: [
{header: "Author", width: 120, dataIndex: 'Author', sortable: true},
{header: "Title", width: 180, dataIndex: 'Title', sortable: true},
{header: "Manufacturer", width: 115, dataIndex: 'Manufacturer', sortable: true},
{header: "Product Group", width: 100, dataIndex: 'ProductGroup', sortable: true}
],
renderTo:'example-grid', width:540, height:200
}); store.load();
});

xml file :


<?xml version="1.0" encoding="UTF-8"?>
<ItemSearchResponse xmlns="http://webservices.amazon.com/AWSECommerceService/2006-06-28">
<OperationRequest>
<HTTPHeaders>
<Header Name="UserAgent"
Value="Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Avant Browser; Avant Browser; .NET CLR 1.0.3705; .NET CLR 2.0.50727; .NET CLR 1.1.4322; Media Center PC 4.0; InfoPath.2)"></Header>
</HTTPHeaders>
<RequestId>18CZWZFXKSV8F601AGMF</RequestId>
<Arguments>
<Argument Name="Service" Value="AWSECommerceService"></Argument>
<Argument Name="AssociateTag" Value="ws"></Argument>
<Argument Name="SearchIndex" Value="Books"></Argument>
<Argument Name="Author" Value="Sidney Sheldon"></Argument>
<Argument Name="SubscriptionId" Value="1A7XKHR5BYD0WPJVQEG2"></Argument>
<Argument Name="Version" Value="2006-06-28"></Argument>
<Argument Name="Operation" Value="ItemSearch"></Argument>
</Arguments>
<RequestProcessingTime>1.05041599273682</RequestProcessingTime>
</OperationRequest>
<Items>
<Request>
<IsValid>True</IsValid>
<ItemSearchRequest>
<Author>Sidney Sheldon</Author>
<SearchIndex>Books</SearchIndex>
</ItemSearchRequest>
</Request>
<TotalResults>203</TotalResults>
<TotalPages>21</TotalPages>
<Item>
<ASIN>0446355453</ASIN>
<DetailPageURL>
http://www.amazon.com/gp/redirect.html%3FASIN=0446355453%26tag=ws%26lcode=xm2%26cID=2025%26ccmID=165953%26location=/o/ASIN/0446355453%253FSubscriptionId=1A7XKHR5BYD0WPJVQEG2
</DetailPageURL>
<ItemAttributes>
<Author>Sidney Sheldon</Author>
<Manufacturer>Warner Books</Manufacturer>
<ProductGroup>Book</ProductGroup>
<Title>Master of the Game</Title>
</ItemAttributes>
</Item>
<Item>
<ASIN>0446613657</ASIN>
<DetailPageURL>
http://www.amazon.com/gp/redirect.html%3FASIN=0446613657%26tag=ws%26lcode=xm2%26cID=2025%26ccmID=165953%26location=/o/ASIN/0446613657%253FSubscriptionId=1A7XKHR5BYD0WPJVQEG2
</DetailPageURL>
<ItemAttributes>
<Author>Sidney Sheldon</Author>
<Manufacturer>Warner Books</Manufacturer>
<ProductGroup>Book</ProductGroup>
<Title>Are You Afraid of the Dark?</Title>
</ItemAttributes>
</Item>
</Items>
</ItemSearchResponse>

this solves your problem ?

AndreasS
23 Jan 2011, 2:35 AM
Well, ok, but is not following the part where the XML gets loaded:
Ext.onReady(function(){
var store = new Ext.data.Store({ url: 'sheldon.xml',
reader: new Ext.data.XmlReader({ record: 'Item', id: 'ASIN', totalRecords: '@total'},
[
{name: 'Author', mapping: 'ItemAttributes > Author'},
'Title', 'Manufacturer', 'ProductGroup'
]
)
});

That works for me as well since sheldon.xml does exist on server side in the directory where the XML is stored, too. I just don't want to read sheldon.xml. I want the XML load from "http://www.sedlmeier-consulting.com/uniJetScripts/MGrqispi.dll?AppName=AjaxSample&PrgName=Sheldon"

Thats not really a webservice, but it is an application running on server side which returns "sheldon.xml" with Content-Type set to "text/xml".

Andreas