title: How to generate XML file from dataset using XSD and MVC
body: <p>I have an XSD file which references other XSD files. It is used by a tomcat application to generate an XML file with water sample results.
  In MVC application I need to query the database, get rows back, and turn them into an XML document that is formatted by referencing the XSD file. I'm at a point where the only solution I can think of is to have an existing XML file and put tags and load into a string and loop through the string replacing the tags with the row's values.</p>
  
  <p>Is there anything in .NET MVC5 that can do something like this? I am stumped. 
  Below is some relevant pieces.</p>
  
  <p>==========================================</p>
  
  <h1>XML file at top looks like this:</h1>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;EN:eDWR xmlns:EN="urn:us:net:exchangenetwork"
      xmlns:SDWIS="http://www.epa.gov/sdwis"
      xmlns:ns3="http://www.epa.gov/xml" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&gt;
      &lt;EN:Submission EN:submissionFileCreatedDate="2012-07-21"
          EN:submissionFileName="B_14271BJB.csv" EN:submissionID="1"&gt;
          &lt;EN:LabReport&gt;
              &lt;EN:LabIdentification&gt;
                  &lt;EN:LabAccreditation&gt;
                      &lt;EN:LabAccreditationIdentifier&gt;OR100024&lt;/EN:LabAccreditationIdentifier&gt;
                      &lt;EN:LabAccreditationAuthorityName&gt;STATE&lt;/EN:LabAccreditationAuthorityName&gt;
                  &lt;/EN:LabAccreditation&gt;
              &lt;/EN:LabIdentification&gt;
              &lt;EN:Sample&gt;
                  &lt;SDWIS:RecordID&gt;155628&lt;/SDWIS:RecordID&gt;
                  &lt;EN:SampleIdentification&gt;
                      &lt;EN:LabSampleIdentifier&gt;123321&lt;/EN:LabSampleIdentifier&gt;
                      &lt;EN:PWSIdentifier&gt;OR4100237&lt;/EN:PWSIdentifier&gt;
                      &lt;EN:PWSFacilityIdentifier&gt;DIST-A&lt;/EN:PWSFacilityIdentifier&gt;
                      &lt;EN:SampleRuleCode&gt;TC&lt;/EN:SampleRuleCode&gt;
                      &lt;EN:SampleMonitoringTypeCode&gt;RP&lt;/EN:SampleMonitoringTypeCode&gt;
  </code></pre>
  
  <p>===================================</p>
  
  <h1>xsd file complete. It references other xsd files in same folder:</h1>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;!-- edited with XMLSPY v5 rel. 4 U (http://www.xmlspy.com) by Leslie Flagler (SAIC) --&gt;
  &lt;xsd:schema targetNamespace="urn:us:net:exchangenetwork" xmlns:SDWIS="http://www.epa.gov/sdwis" xmlns:EN="urn:us:net:exchangenetwork" xmlns:facid="http://www.epa.gov/xml" xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="qualified" version="3.0"&gt;
      &lt;xsd:annotation&gt;
          &lt;xsd:documentation/&gt;
      &lt;/xsd:annotation&gt;
      &lt;xsd:include schemaLocation="./EDWR_MetaData.xsd"/&gt;
      &lt;xsd:include schemaLocation="./EDWR_ContactPoint.xsd"/&gt;
      &lt;xsd:include schemaLocation="./SDWIS_LabReport.xsd"/&gt;
      &lt;xsd:include schemaLocation="./EDWR_Authentication.xsd"/&gt;
      &lt;xsd:element name="eDWR"&gt;
          &lt;xsd:annotation&gt;
              &lt;xsd:documentation&gt;This is the standard regulatory schema
                  approved by the USEPA and multi-state Lab to State
                  Drinking Water Integrated Project Team&lt;/xsd:documentation&gt;
          &lt;/xsd:annotation&gt;
          &lt;xsd:complexType&gt;
              &lt;xsd:annotation&gt;
                  &lt;xsd:documentation&gt;This is enfoTech EDWR schema&lt;/xsd:documentation&gt;
              &lt;/xsd:annotation&gt;
              &lt;xsd:sequence&gt;
                  &lt;xsd:element ref="EN:MetaData" minOccurs="0"/&gt;
                  &lt;xsd:element ref="EN:Receiver" minOccurs="0"/&gt;
                  &lt;xsd:element ref="EN:Sender" minOccurs="0"/&gt;
                  &lt;xsd:element ref="EN:Submission"/&gt;
              &lt;/xsd:sequence&gt;
          &lt;/xsd:complexType&gt;
      &lt;/xsd:element&gt;
      &lt;xsd:complexType name="SubmissionDataType"&gt;
          &lt;xsd:annotation&gt;
              &lt;xsd:documentation&gt;Transction information&lt;/xsd:documentation&gt;
          &lt;/xsd:annotation&gt;
          &lt;xsd:sequence&gt;
              &lt;xsd:element ref="EN:LabReport" minOccurs="0" maxOccurs="unbounded"/&gt;
              &lt;xsd:element ref="EN:SubmissionCertification" minOccurs="0"/&gt;
          &lt;/xsd:sequence&gt;
          &lt;xsd:attribute name="submissionID" type="xsd:string"/&gt;
          &lt;xsd:attribute name="submissionFileName" type="xsd:string"/&gt;
          &lt;xsd:attribute name="submissionFileCreatedDate" type="xsd:date"/&gt;
      &lt;/xsd:complexType&gt;
      &lt;xsd:element name="MetaData" type="EN:MetaDataDataType"&gt;
          &lt;xsd:annotation&gt;
              &lt;xsd:documentation&gt;General information about the schema&lt;/xsd:documentation&gt;
          &lt;/xsd:annotation&gt;
      &lt;/xsd:element&gt;
      &lt;xsd:element name="Receiver" type="EN:ContactPointDataType"&gt;
          &lt;xsd:annotation&gt;
              &lt;xsd:documentation&gt;Regulatory agency and contact to receive
                  the e-DWR submission file&lt;/xsd:documentation&gt;
          &lt;/xsd:annotation&gt;
      &lt;/xsd:element&gt;
      &lt;xsd:element name="Sender" type="EN:ContactPointDataType"&gt;
          &lt;xsd:annotation&gt;
              &lt;xsd:documentation&gt;The sender of the e-DWR submission file&lt;/xsd:documentation&gt;
          &lt;/xsd:annotation&gt;
      &lt;/xsd:element&gt;
      &lt;xsd:element name="LabReport" type="EN:LabReportDataType"&gt;
          &lt;xsd:annotation&gt;
              &lt;xsd:documentation&gt;Lab Analysis Report (includes Lead and
                  Copper Report, Water Quality Parameters, and
                  Bacteriological Analysis Report, etc)&lt;/xsd:documentation&gt;
              &lt;xsd:documentation&gt;Chemical Analysis Report (includes Lead
                  and Copper Report, Water Quality Parameters, and
                  Bacteriological Analysis Report)&lt;/xsd:documentation&gt;
          &lt;/xsd:annotation&gt;
      &lt;/xsd:element&gt;
      &lt;xsd:element name="SubmissionCertification" type="EN:AuthenticationDataType"&gt;
          &lt;xsd:annotation&gt;
              &lt;xsd:documentation&gt;Submission Certification&lt;/xsd:documentation&gt;
          &lt;/xsd:annotation&gt;
      &lt;/xsd:element&gt;
      &lt;xsd:element name="Submission" type="EN:SubmissionDataType"&gt;
          &lt;xsd:annotation&gt;
              &lt;xsd:documentation&gt;Information pertaining to a drinking
                  water report submission&lt;/xsd:documentation&gt;
          &lt;/xsd:annotation&gt;
      &lt;/xsd:element&gt;
  &lt;/xsd:schema&gt;
  </code></pre>