You need to post your XML string to a controller action to allow you to hook into your database service so you can save it. I'd use an AJAX post like shown in the example below:
$.ajax({
type: "POST",
url: "@Url.Action("YourSaveAction", "YourController")",
data: { xmlString: myXMLVar}
});
Looking at what you are attempting, I'd much sooner handle the XML manipulation outside of JQuery. I'd look to use some form of XML serialization inside your application in order to represent the model of your sales and invoices. You can then manipulate strongly typed objects rather than extracting properties via JQuery.
Below is an example of how you could do this.
First create a class marked as serializable to store your order details.
[XmlRoot]
[Serializable]
public class SalesInvoice
{
[XmlElement]
public List<Detail> Details { get; set; }
public SalesInvoice()
{
Details = new List<Detail>();
}
}
[Serializable]
public class Detail
{
[XmlElement]
public string Product { get; set; }
[XmlElement]
public string Quantity { get; set; }
}
Assuming you have raw XML somewhere, you can then serialize your XML into a Sales class. For this example I'm reading the XML locally from a file, but you can plug in your source.
var configStream = File.OpenRead(@"C:\invoice.xml");
var reader = new StreamReader(configStream);
var xmlString = reader.ReadToEnd();
var stringReader = new StringReader(xmlString);
var newInvoice = (SalesInvoice)serializer.Deserialize(stringReader);
This will then give you a strongly typed object which you can now use to write the data out to the database.
For your MVC application, I would have a ViewModel something like the example below:
public class SalesModel
{
public SalesInvoice Invoice { get; set; }
}
This is what could be manipulated in your View and finally posted to a controller to save the data to the database.
Your controller might look something like this:
[HttpPost]
public void SaveSalesInvoice(SalesModel model)
{
var myDataService = new DataService();
myDataService.SaveSalesInvoice(model.Invoice);
}
I presume you would have some kind of service in the example above that takes the SalesInvoice object as a parameter allowing you to save its data to the database.
Having re-read again, it looks like you may want to save the whole XML into the database. If this is the case, then you can de-serialize the object created to get the XML string and save that.
var serializer = new XmlSerializer(typeof(SalesInvoice));
var writer = new StringWriter();
serializer.Serialize(writer, invoice);
var xml = writer.ToString();
Well I hope this makes sense and helps....and that I've understood your need :)