title: Generating XML with an xsd in VS2010 using LINQ
body: <p>I've used Linq2SQL lots and am familiar with most of the concepts (up to and including extending an ObjectContext) but with regards to Linq2XML, I'm a little lost.</p>
  
  <p>I now have a need to generate some complex XML and I'd like to use the simplicity of LINQ.</p>
  
  <p>Previously, I've used XMLDocuments and programatically built up elements - I'm hoping I can get something a little more elegant.</p>
  
  <p>I've been given a complex schema in the form of 15-odd xsds - most of which import at least one other xsd (the common data types) and some of which import each other</p>
  
  <p>So I've got something like:</p>
  
  <p>File 1..n</p>
  
  <pre><code>&lt;xsd:schema targetNamespace="http://www.SomeCompany.com"  
      xmlns:SomeCompany="http://www.SomeCompany.com/datatypes_EA"  
      xmlns="http://www.SomeCompany.com" xmlns:dct="http://www.SomeCompany.com/DCTRequestdatatypes"  
      xmlns:xsd="http://www.w3.org/2001/XMLSchema"
      elementFormDefault="unqualified"&gt;
      &lt;xsd:import namespace="http://www.SomeCompany.com/datatypes_EA"
          schemaLocation="datatypes_EA.xsd" /&gt;
          &lt;xsd:import namespace="http://www.SomeCompany.com/DCTRequestdatatypes"
          schemaLocation="DCTRequestdatatypes.xsd" /&gt;
      &lt;xsd:element name="DCTRequest"&gt;
          &lt;xsd:complexType&gt;
              &lt;blah which references types stored in datatypes_EA.xsd&gt;
          &lt;/xsd:complexType&gt;
      &lt;/xsd:element&gt;
  &lt;/xsd:schema&gt;
  </code></pre>
  
  <p>and another file (DataTypes_EA.xsd) which contains the common data types.</p>
  
  <p>I've had to tweak the <code>&lt;import&gt;</code>s to fix path issues but VS2010 now displays 0 errors (and nothing is underlined in the editor)</p>
  
  <p>The various files 1...n define the xml that is required to hit a web service - as such there's no common root (There's an xsd for request type 1, request type 2, etc.)</p>
  
  <p>I've found the xsd.exe tool to generate classes but if I point it at the schema for (say) request type 1, I get lots of schema validation warnings - saying that it can't find the common data types (like it's not reading the import statement) and fails to generate anything.</p>
  
  <p>Ideally, I'd like to skip generating classes entirely but will accept it if required.</p>
  
  <p>In short, how do I get from where I am to writing something like:</p>
  
  <pre><code>Dim Root as new DCTRequest with {.Property = "SomeValue"}
  ...
  Dim ElementsWithSomething = A.SomeElementCollection.Where(function(x) x.PropertyName = "Something")
  Dim FinalXML = A.Tostring (or serialize or whatever)
  </code></pre>
  
  <p>Am I approaching this wrong?</p>
  
  <p>Thanks in advance for any help</p>