There are many examples of using the Ext xmlreader to get xml data into a datastore on the client, however I wanted to do the reverse and allow my CRUD application to update the modified datastore back to the server, updated with user changes.
On the client I created a 'serialize' function to convert the datastore to XML, and then did an Ext.data.Connection to post the data to the server.
SaveDStoServer :function(ds) {
var prog = Ext.MessageBox.wait("Saving data to server");
var ds_serialized= myscope.SerializeDS(ds);
var serv= new Ext.data.Connection();
serv.request({
url: "Service.asmx/Savedata",
params: {myID: 123, datastore:ds_serialized},
method: 'POST',
scope: this,
callback: function(options, success, response){
prog.hide();
if (success){
var xml = response.responseXML;
}
else {
if( response.status == -1 )
Ext.MessageBox.alert('Error on save','The server did not respond.')
else Reports Validator 1.17:: The XML dataset can also be consumed by SQL 2000 Reporting Services; however, this requires you to write a custom Data Processing Extension as SQL 2000 http://wareseeker.com/Network-Internet/reports-validator-1.17.zip/1ffbc68c0HOME |
Ext.MessageBox.alert('Error on save',response.responseText)
}
}
});
},
SerializeDS : function (ds) {
var columns = ds.fields.keys; // get columns from data store
var retdata ='';
ds.each ( function (rec) {
retdata +="";
for (var i=0; i< columns.length; ++ i)
retdata += "<" + columns[i] + ">" + rec.data[columns[i]] + "" + columns[i] + ">"
retdata += "";
});
retdata += "";
return ""+retdata;
},
On the server side web service method, I create an XML document, create a reader and then read into the dataset. I tried using 'XMLdatadocument' but if did not seem able to create a schema and had an empty dataset. This may not be the most efficient way but it seems to work well. As always, be aware of web service parameter verification to prevent SQL injection.
[WebMethod]
public String Savedata (String SchID, String datastore)
{
DataSet ds = new DataSet();
XmlDocument doc = new XmlDocument();
// Load the xml into an XmlDocument
doc.LoadXml(datastore);
StringReader sreader = new StringReader(doc.DocumentElement.OuterXml);
ds.ReadXml(sreader);
foreach (DataRow row in dsCraft.Tables[0].Rows)
{
System.Diagnostics.Debug.WriteLine(row[0] + " " + row[1]);
}
return "success";
}
Something that you might look at is skipping the xml serialization alltogether.
I send records to the a web service like this:
var newData = ;
Ext.getCmp("StructSettingsMain_AddMultiDivisions_gridDivisionA dd").getStore()
.each(function(Record) {
newData.push(Record.data);
});
// debugger;
var r = Ext.Ajax.request( {
method : "POST",
url : "WebServices/CompanyStructureTree.asmx/DivisionMultiAdd",
params : Ext.util.JSON.encode( {
jsonDivList : Ext.util.JSON.encode(newData)
}),
async : false
});
On the server side, I do something like this:
Public Function DivisionMultiAdd(ByVal jsonDivList As String) As String
If Not Me.User.Identity.IsAuthenticated Then
Return String.Empty
End If
Dim div As Object
Dim mySerializer As New System.Web.Script.Serialization.JavaScriptSerializ er
Dim DivList As Array = mySerializer.DeserializeObject(jsonDivList)
For Each div In DivList
Division.Insert(Code:=div.item("Code"), Name:=div.item("Name"), Product:=div.item("Product"), Number:=div.item("Number"), Rank:=div.item("Rank"))
Next
You might also look at this thread (http://extjs.com/forum/showthread.php?p=34075) to see Animal's serialization fn.
Red Hat's Rough Recovery From CFO Exit
Windows Live Finds a New, Pre-installed Home |