The .NET framework provides several different mechanisms for moving XML data into a relational database. This sample shows how to take a real XML document (minus real names, addresses, and credit card numbers) generated from a YahooStores site and move it into existing SQL Server database tables.
Because the XML document does not match the database schema, it is transformed to fit the schema using XSLT and then read into a DataSet. The DataSet is first loaded with the database schema which is generated on the fly. SqlCommand objects are then dynamically created and associated with a SqlDataAdapter which inserts the DataSet data into three relational database tables.
Note: This is one of several solutions for moving complex hierarchical XML documents into relational database tables. Because this solution relies on XSLT it may perform poorly when extremely large XML documents need to be moved into a database due to the XML document being loaded into memory for the transformation.
|