title: Parse/Shred Huge Complex XML to SQL Server 2008 Database (30+ tables)
body: <p>I read this already: <a href="https://stackoverflow.com/questions/61233/the-best-way-to-shred-xml-data-into-sql-server-database-columns">The Best Way to shred XML data into SQL Server database columns</a>  and <a href="https://stackoverflow.com/questions/223376/looking-for-a-good-bulk-insert-xml-shredding-example-for-sql-2005">Looking for a good Bulk Insert XML Shredding example for SQL 2005</a>. </p>
  
  <p>The differences of why I'm posting is that I'm using BizTalk 2009 and SQL 2008.  </p>
  
  <p>I'm receiving a huge XML structure from a vendor using BizTalk. The client has normalized the XML structure into about 30 tables on a MS/SQL Server 2008 database. </p>
  
  <p>Is there any magic solution yet? </p>
  
  <p>Seems like to me these are the options: </p>
  
  <p>1) BizTalk SQL adapter only good for simple flat databases (not a lot of joins and one-to-many relationships). </p>
  
  <p>2) Write a WCF program 
      a) use LINQ and expose the LINQ object 
      b) use traditional XML DOM or SAX parsing and build ADO.NET to store in database </p>
  
  <p>3) Write a complex Stored Proc that uses Open/XML. </p>
  
  <p>4) Store the database temporarily in an SQL/XML Column, then use some other tool to "shred and normalize" the data.  Is there anything in SSIS that would do this? </p>
  
  <p>5) Leave the data in an XML column, and use XML indices and never normalize it.  Embed the ugly XQuery/Xpath statements in a view.  Not sure if response time or queries would be adequate.  Might take as long to generate the xqueries and views as it would to do one of the other steps above.  </p>
  
  <p>I'm guessing that #2 or #3 would take at least one or two hours per table, thus if we have 30 tables, at least 30 (if not 60 hours) of various tedious boring and error-prone work.  </p>
  
  <p>Thanks,</p>
  
  <p>Neal Walters </p>
  
  <p>Update 12/23: Some sample data: </p>
  
  <pre><code> &lt;ns0:ValAgg xmlns:va="http://msbinfo.com/expresslync/rct/valuation" xmlns:ns0="http://TFBIC.RCT.BizTalk.Orchestrations.ValAgg"&gt;
  - &lt;MainStreetValuation xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://msbinfo.com/expresslync/rct/valuation"&gt;
  &lt;ValuationIdentifier&gt;
    &lt;RecordId&gt;1928876&lt;/RecordId&gt; 
    &lt;PolicyNumber&gt;ESTIMATE-1928876&lt;/PolicyNumber&gt; 
    &lt;VersionId&gt;6773220&lt;/VersionId&gt; 
    &lt;/ValuationIdentifier&gt;
    &lt;RecordType&gt;EST&lt;/RecordType&gt; 
    &lt;PolicyStatus&gt;Complete&lt;/PolicyStatus&gt; 
    &lt;DataSource&gt;WEB&lt;/DataSource&gt; 
     &lt;bunch more here/&gt; 
  &lt;valuationAggregateFlat xmlns="http://tempuri.org/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;
    &lt;policyNumber&gt;ESTIMATE-1928876&lt;/policyNumber&gt; 
    &lt;recordId&gt;1928876&lt;/recordId&gt; 
    &lt;versionId&gt;6773220&lt;/versionId&gt; 
    &lt;updateTimeStamp&gt;2009-12-14T14:50:30.743&lt;/updateTimeStamp&gt; 
    &lt;replacementCost&gt;166129&lt;/replacementCost&gt; 
    &lt;yearBuilt&gt;1999&lt;/yearBuilt&gt; 
    &lt;totalLivingAreaSqFt&gt;2000&lt;/totalLivingAreaSqFt&gt; 
    &lt;primaryRCTRoofTypeCode&gt;15012&lt;/primaryRCTRoofTypeCode&gt; 
    &lt;TOPSRoofType&gt;COPR&lt;/TOPSRoofType&gt; 
    &lt;StdFireRoofType&gt;COPR&lt;/StdFireRoofType&gt; 
    &lt;primaryRTCConstructionTypeCode&gt;10016&lt;/primaryRTCConstructionTypeCode&gt; 
    &lt;constructionType&gt;BV&lt;/constructionType&gt; 
    &lt;hailProofIndicator&gt;false&lt;/hailProofIndicator&gt; 
    &lt;anyWoodRoofIndicator&gt;false&lt;/anyWoodRoofIndicator&gt; 
    &lt;allMetalRoofIndicator&gt;true&lt;/allMetalRoofIndicator&gt; 
    &lt;/valuationAggregateFlat&gt;
  &lt;/ns0:ValAgg&gt;
  </code></pre>
  
  <p>Where you see "MainStreetValuation" could also be a couple of other complex types, such as "HighValueValuation" where the entire structure is different for homes that have fancy stuff. </p>