PDA

View Full Version : Post Grid data in xml format to server



pitviper202002
24 Jul 2009, 3:52 AM
Hi ,

I am using Ext 3.0 could anyone help me regarding sending grid data to server in xml format

Regards,
Viper

Condor
24 Jul 2009, 3:55 AM
You'll have to build the XML yourself and use something like:

var data = '<?xml version="1.0" encoding="UTF-8"?><data>value</data>';
Ext.Ajax.request({
url: '...',
xmlData: data,
success: function(){
...
}
});

pitviper202002
24 Jul 2009, 4:26 AM
my grid is a as follows

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",
dataIndex : 'Author'
}, {
header : "Title",
dataIndex : 'Title'
}, {
header : "Manufacturer",
dataIndex : 'Manufacturer'
}, {
header : "Product Group",
dataIndex : 'ProductGroup'
}]
});

store.load();


Could you plz tell me now how to send the all data from store as xml to the server

Condor
24 Jul 2009, 4:53 AM
I already told you: You have to create the XML as text, e.g.

var tpl = new Ext.XTemplate(
'<?xml version="1.0" encoding="UTF-8"?>',
'<ItemSearchResponse xmlns="http://webservices.amazon.com/AWSECommerceService/2006-06-28">',
'<Items>',
'<tpl for=".">',
'<ASIN>{id}</ASIN>',
'<ItemAttributes>',
'<Author>{data.Author}</Author>',
'<Manufacturer>{data.Manufacturer}</Manufacturer>',
'<ProductGroup>{data.ProductGroup}</ProductGroup>',
'<Title>{data.Title}</Title>',
'</ItemAttributes>',
'</tpl>',
'</Items>',
'</ItemSearchResponse>');
Ext.Ajax.request({
url: '...',
xmlData: tpl.apply(store.getRange()),
success: function(){
...
}
});

pitviper202002
24 Jul 2009, 11:30 PM
Getting an error data is undefined if i use data.Author in the XTemplate and when i use store.data.Author i get the xml as follows .Could any one help

<?xml version="1.0" encoding="UTF-8"
?><ItemSearchResponse xmlns="http://webservices.amazon.com/AWSECommerceService
/2006-06-28"><Items><ASIN>0446355453</ASIN><ItemAttributes><Author></Author><Manufacturer></Manufacturer
><ProductGroup></ProductGroup><Title></Title></ItemAttributes><ASIN>0446613657</ASIN><ItemAttributes
><Author></Author><Manufacturer></Manufacturer><ProductGroup></ProductGroup><Title></Title></ItemAttributes
><ASIN>0446357421</ASIN><ItemAttributes><Author></Author><Manufacturer></Manufacturer><ProductGroup>
</ProductGroup><Title></Title></ItemAttributes><ASIN>0446607207</ASIN><ItemAttributes><Author></Author
><Manufacturer></Manufacturer><ProductGroup></ProductGroup><Title></Title></ItemAttributes><ASIN>0446357448
</ASIN><ItemAttributes><Author></Author><Manufacturer></Manufacturer><ProductGroup></ProductGroup><Title
></Title></ItemAttributes><ASIN>0446532673</ASIN><ItemAttributes><Author></Author><Manufacturer></Manufacturer
><ProductGroup></ProductGroup><Title></Title></ItemAttributes><ASIN>0446356573</ASIN><ItemAttributes
><Author></Author><Manufacturer></Manufacturer><ProductGroup></ProductGroup><Title></Title></ItemAttributes
><ASIN>0060198346</ASIN><ItemAttributes><Author></Author><Manufacturer></Manufacturer><ProductGroup>
</ProductGroup><Title></Title></ItemAttributes><ASIN>0446354732</ASIN><ItemAttributes><Author></Author
><Manufacturer></Manufacturer><ProductGroup></ProductGroup><Title></Title></ItemAttributes><ASIN>0446341916
</ASIN><ItemAttributes><Author></Author><Manufacturer></Manufacturer><ProductGroup></ProductGroup><Title
></Title></ItemAttributes></Items></ItemSearchResponse>

pitviper202002
25 Jul 2009, 1:13 AM
Hi

By changing data.Author to values.data.Author the proper XMl was generated.Thanks for all the help and support.


var tpl = new Ext.XTemplate(
'<?xml version="1.0" encoding="UTF-8"?>',
'<ItemSearchResponse xmlns="http://webservices.amazon.com/AWSECommerceService/2006-06-28">',
'<Items>',
'<tpl for=".">',
'<ASIN>{id}</ASIN>',
'<ItemAttributes>',
'<Author>{values.data.Author}</Author>',
'<Manufacturer>{values.data.Manufacturer}</Manufacturer>',
'<ProductGroup>{values.data.ProductGroup}</ProductGroup>',
'<Title>{values.data.Title}</Title>',
'</ItemAttributes>',
'</tpl>',
'</Items>',
'</ItemSearchResponse>');
Regards,
Viper

cayenne_08
19 May 2011, 11:48 AM
I am trying to use XTemplate to POST custom XML.

In my XMLWriter:

(function() {
Q.dxi.QXmlWriter = Ext.extend(Ext.data.XmlWriter, {
constructor: function(config){
Q.dxi.QXmlWriter.superclass.constructor.call(this,
Ext.applyIf(config, {
writeAllFields: true,
render : function(params, baseParams, data) {
formatDate(data);
var tpl = new Ext.XTemplate(
'<?xml version="1.0" encoding="ISO-8859-15"?>',
'<Event xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ThrottleEventType">',
'<EventTypeName>{data.EventTypeName.value}</EventTypeName>',
'<StartDate>{data.StartDate.value}</StartDate>',
'<EndDate>{values.data.EndDate.value}</EndDate>',
'<Title>{data.Title.value}</Title>',
'<Bandwidth>{data.Bandwidth.value}</Bandwidth>',
'<EventId>{data.EventId.value}</EventId>',
'</Event>');
Q.dxi.QXmlWriter.superclass.render.call(this, params, baseParams, tpl);
}
}));
}
});
Ext.reg('QXmlWriter', Q.dxi.QXmlWriter);
}

I get the following error:

XML Parsing Error: not well-formed Location: moz-nullprincipal:{1f5f63f9-60fc-4caa-940c-6fee33f420b8} Line Number 1, Column 53:

...ml version="1.0" encoding="ISO-8859-15"?><Event><></></Event>
...-------------------------------------------------^

Source
<?xml version="1.0" encoding="ISO-8859-15"?><Event><></></Event>

Any ideas?

cayenne_08
25 May 2011, 10:26 AM
I want to replace hard coded "FooType" below to a parameter that can be set dynamically

<code>
var tpl = new Ext.XTemplate('<tpl for="."><\u003fxml version="{version}" encoding="{encoding}"\u003f><tpl if="documentRoot"><{documentRoot}><tpl for="baseParams"><tpl for="."><{name}>{value}</{name}></tpl></tpl></tpl><tpl if="records.length&gt;1"><{root}></tpl><tpl for="records"><{parent.record} xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="FooType"><tpl for="."><{name}>{value}</{name}></tpl></{parent.record}></tpl><tpl if="records.length&gt;1"></{root}></tpl><tpl if="documentRoot"></{documentRoot}></tpl></tpl>');
params.xmlData = tpl.applyTemplate({
version: this.xmlVersion,
encoding: this.xmlEncoding,
documentRoot: (baseParams.length > 0 || this.forceDocumentRoot === true) ? this.documentRoot : false,
record: this.meta.record,
root: this.root,
baseParams: baseParams,
records: (Ext.isArray(data[0])) ? data : [data],
type: 'MyType'
});
</code>
How do I do this?

Thanks!