title: C# XML document remove elements that fail schema - preferably split the file into valid and invalid
body: <p>I have some user data coming out a system that needs to be fed into another as XML. There is an schema defined but the target system will accept the XML regardless of whether it passes or fails the schema, but instead fails silently.</p>
  
  <p>I'm using a script component in SSIS and could write my own C# validation but I'm wondering if anyone can think of a way to validate the XML against the schema then split the XML into two files. One with valid users and another with invalid users? The XSD has custom types, Regex patterns etc. so I'd like to leverage what's already there if possible. I'm after an answer in C# preferably</p>
  
  <pre><code>&lt;Users&gt;
    &lt;User&gt;
      &lt;FirstName/&gt;
      &lt;LastName/&gt;
      &lt;Etc../&gt;
    &lt;/User&gt;
  &lt;/Users&gt;
  
  &lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema"&gt;
    &lt;xs:element name="Users"&gt;
      &lt;xs:complexType&gt;
        &lt;xs:sequence&gt;
          &lt;xs:element name="User"&gt;
            &lt;xs:complexType&gt;
              &lt;xs:sequence&gt;
                &lt;xs:element name="FirstName" /&gt;
                &lt;xs:element name="LastName" /&gt;
                &lt;xs:element name="Etc.." /&gt;
              &lt;/xs:sequence&gt;
            &lt;/xs:complexType&gt;
          &lt;/xs:element&gt;
        &lt;/xs:sequence&gt;
      &lt;/xs:complexType&gt;
    &lt;/xs:element&gt;
  &lt;/xs:schema&gt;
  </code></pre>