title: Create Valid XML from XSD Loaded at Runtime (without xsd.exe)
body: <blockquote>
    <p><strong>Possible Duplicate:</strong></p>
    
    <ul>
    <li><a href="https://stackoverflow.com/questions/2140828/programmatically-create-xml-file-from-xsd">Programmatically Create XML File From XSD</a>  </li>
    <li><a href="https://stackoverflow.com/questions/307616/xml-instance-generation-from-xml-schema-xsd">XML instance generation from XML schema (xsd)</a></li>
    <li><a href="https://stackoverflow.com/questions/17106/how-to-generate-sample-xml-documents-from-their-dtd-or-xsd/730208#730208">How to generate sample XML documents from their DTD or XSD?</a></li>
    </ul>
  </blockquote>
  
  
  
  <p>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.</p>
  
  <p>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.</p>
  
  <p><strong>My question is</strong>: 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). </p>
  
  <p>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.</p>
  
  <p><strong>[update]</strong> 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.</p>