
|
Loading XML Files Should be a lot easier than it is, but if you look for this on the web, you will get confused. Put simple - if you have an embedded DTD in the file it won't work within SSIS - so the easiest solution - don't use SSIS use SELECT * FROM OPENROWSET( This translates as create a table with a column of data type XML INSERT INTO T(XmlCol) If there is an embedded dtd you need to convert (and the column is called bulkcolumn) INSERT INTO T(XmlCol) Using convert(xml,columnname,2) gives limited dtd support "Enable limited internal DTD subset processing. If enabled, the server can use the following information that is provided in an internal DTD subset to perform nonvalidating parse operations.
The parser will ignore external DTD subsets. It also does not evaluate the XML declaration to see whether the standalone attribute is set yes or no, but instead parses the XML instance as if it is a stand-alone document. This gives you a single row holding the entire document - not very usable (example is for an xml feed for shopwhale) - we can use cross apply to convert this into xml rows in a new table -- Cross apply to get 1 row per product We now have all the xml rows in the table and can then extract the components - if you do a select top n from the transformed table you can see the structure - cliick on the xml and it's loaded in a new pane in studio. SELECT ProductName.value('(//product/offer_id)[1]', 'int') as Offer_id Hey presto we have the rows in a table in a usable format - wrap this into a stored procedure - pass in the name of the xml document and you can end up with a table that you can use!
|