title: Multiple Xsd schemas in 1 file
body: <p>I have multiple Xsd schema files (small ones) and would like to somehow combine them into 1 big file, I was thinking of an xml file with 1 node for each Xsd schema content, in the C# code selecting the corresponding section and validating against it. 
  The problem is I can see a warning "The global element 'xxx' has already been declared. " when opening the Xml file using Visual studio (I'm definitely not an Xsd expert; I indeed have the same element repeated). </p>
  
  <p>Any ideas of the correctness of this approach ?
  Shall I use CData for Xsd content may be instead ?</p>
  
  <p>Examples of Xml files:</p>
  
  <p>Xml 1: </p>
  
  <pre><code>&lt;resource xmlns=""&gt;
    &lt;identifier&gt;5401902302111&lt;/identifier&gt;
    &lt;product&gt;printer&lt;/product&gt;
    &lt;requestedby /&gt;
  &lt;/resource&gt;
  </code></pre>
  
  <p>Xml 2:</p>
  
  <pre><code>&lt;resource xmlns=""&gt;
    &lt;identifier&gt;5401902302112&lt;/identifier&gt;
    &lt;email&gt;someone@em.com&lt;/email&gt;
  &lt;/resource&gt;
  </code></pre>
  
  <p>Xsd 1:</p>
  
  <pre><code>&lt;xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema"&gt;
              &lt;xs:element name="resource"&gt;
                &lt;xs:complexType&gt;
                  &lt;xs:sequence&gt;
                    &lt;xs:element type="xs:long" name="identifier"/&gt;
                    &lt;xs:element type="xs:string" name="requestedby"/&gt;
                    &lt;xs:element type="xs:string" name="product"/&gt;
                  &lt;/xs:sequence&gt;
                &lt;/xs:complexType&gt;
              &lt;/xs:element&gt;
            &lt;/xs:schema&gt;
  </code></pre>
  
  <p>Xsd 2: </p>
  
  <pre><code>&lt;xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema"&gt;
              &lt;xs:element name="resource"&gt;
                &lt;xs:complexType&gt;
                  &lt;xs:sequence&gt;
                    &lt;xs:element type="xs:long" name="identifier"/&gt;
                    &lt;xs:element type="xs:string" name="email"/&gt;
                  &lt;/xs:sequence&gt;
                &lt;/xs:complexType&gt;
              &lt;/xs:element&gt;
            &lt;/xs:schema&gt;
  </code></pre>
  
  <p>What I want to have in the end: </p>
  
  <pre><code>*&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;resource&gt;
    &lt;resourcedata type="acquisition"&gt;
      &lt;details&gt;
        &lt;xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema"&gt;
          &lt;xs:element name="resource"&gt;
            &lt;xs:complexType&gt;
              &lt;xs:sequence&gt;
                &lt;xs:element type="xs:long" name="identifier"/&gt;
                &lt;xs:element type="xs:string" name="requestedby"/&gt;
                &lt;xs:element type="xs:string" name="product"/&gt;
              &lt;/xs:sequence&gt;
            &lt;/xs:complexType&gt;
          &lt;/xs:element&gt;
        &lt;/xs:schema&gt;
      &lt;/details&gt;
    &lt;/resourcedata&gt;
    &lt;resourcedata type="warningletter"&gt;
      &lt;details&gt;
        &lt;xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema"&gt;
          &lt;xs:element name="resource"&gt;
            &lt;xs:complexType&gt;
              &lt;xs:sequence&gt;
                &lt;xs:element type="xs:long" name="identifier"/&gt;
                &lt;xs:element type="xs:string" name="email"/&gt;
              &lt;/xs:sequence&gt;
            &lt;/xs:complexType&gt;
          &lt;/xs:element&gt;
        &lt;/xs:schema&gt;
      &lt;/details&gt;
    &lt;/resourcedata&gt;
  &lt;/data&gt;*
  </code></pre>
  
  <p>C# code:</p>
  
  <pre><code>var xsdContent =
                  xDoc.Element("resource").Elements("resourcedata")
                      .Where(
                          x =&gt;                            
                              x.Attribute("type").Value == "acquisition")
                      .FirstOrDefault().Element("details").FirstNode.ToString();            
  
  
              var doc = new XDocument(xElementContent);
  
              XmlSchemaSet schemas = new XmlSchemaSet();
              schemas.Add("", XmlReader.Create(new StringReader(xsdContent)));
  
              Console.WriteLine("Validating doc");
              bool errors = false;
              doc.Validate(schemas, (o, e) =&gt;
              {
                  Console.WriteLine("{0}", e.Message);
                  Console.WriteLine("{0}", e.Exception);
                  errors = true;
              });
  
              Console.WriteLine("doc {0}", errors ? "did not validate" : "validated");
  </code></pre>
  
  <p>(<em>xElementContent</em> variable contains Xml content)</p>
  
  <p>Thanks</p>