tags:

views:

123

answers:

1

here's my scenario. XML is stored in SQL DB. I need to allow user to edit different parts of that XML (no insertion, just updates), get notified if something changed (so that I could save the last date file or node was edited) and then save updated XML to DB.

What is the best & quickest approach in this scenario? I was hoping to use data binding expression with XmlDataSource. BUT, it supports only read-only binding (it seems).

Are there any other alternative solutions built into ASP.NET I could use that would allow databinding (with specifying xpath for each control)? or do I need to roll out my own solution?

if roll out my own solution, what's the best way to do it?

+1  A: 

You don't have to roll your own solution since you could easily let the .Net framework do the heavy lifting for you. If databinding is what you are after, then you can use the XSD tool generate a CLR class for you from your XML schema (if it exists).

Generating the class would look something like this:

xsd /c /language:CS XSDSchemaFile.xsd

Once you have that object, do binding as usual on the UI to that object. Once you are ready to propogate those changes to the DB, you can XML serialize the object and push the results back down to the DB.

var serializer = new XmlSerializer(typeof (MyCustomType));

var stream = new MemoryStream();
var xw = new XmlTextWriter(stream, encoding);

serializer.Serialize(xw, instanceOfCustomType);

String xml = encoding.GetString(stream.ToArray());
Josh