Possible Duplicate:
  
  
  Programmatically Create XML File From XSD  
  XML instance generation from XML schema (xsd)
  How to generate sample XML documents from their DTD or XSD?
  




Here's the scenario: I've created an application that hooks into a commercial CRM product using their web service API, which unfortunately has a different schema for every installation, based on how the users create their custom fields. This schema can also be modified at any time. This application will be installed at the customer location, and will need to function even when they change their field structure.

In order to insert or update a record, I first call their Project.GetSchema() method, which returns the XSD file based on the current set of fields, and then I can call the Project.AddProject() method, passing in an XML file containing the project data.

My question is: What's the best way to generate the XML from the XSD file at runtime? I need to be able to check for the existence of fields, and fill them out only if they exist (for instance, if the customer deleted or renamed some fields). 

I really don't want to have the application attempting to recompile classes on the fly using xsd.exe. There simply must be a better way.

[update] My current solution, that I'm working on, is to basically parse out the XSD file myself, since the majority of the schema is going to be the same for each installation. It's just an ugly solution, and I was hoping there was a better way. The biggest problem I have is that their schema uses xsd:sequence, so putting things in a different order always breaks validation.


Question: WPF: disable bindings update on detach
Answer: Whenever we have a UI that enables a user to edit an object, but also provides the possibility of saving or cancelling, we simply need to use another view model class for that view.

Therefore, when editing starts you copy the fields from the current object to the editable properties in the view model. We then leave the user to edit what they want. If they cancel the operation, then we do nothing, as the original object is untouched.

However, if they want to save, then we copy the properties from the edited view model to the original object and save it. Then the view and view model can be disposed of without consequence.