January 17, 2015 at 3:22 pm
Hi, I've read several articles on importing XML into a SQL DB using different methods but I don't know if they are outdated or if one is preferred over the others. My XML file is as follows:
<?xml version="1.0" ?>
<STOREITEMS>
<CREATED>
<CATEGORY id='181' name='Category name'>
<PRODUCT ITEM='7451'>
<WEIGHT>0.50</WEIGHT>
<NAME>Product name</NAME>
<MODEL>Product model</MODEL>
<PRICE>£5.99</PRICE>
<IMAGE>image.jpg</IMAGE>
<DESCRIPTION>Product description.</DESCRIPTION>
</PRODUCT>
</CATEGORY>
</CREATED>
</STOREITEMS>
Any advice on how best to do this would be appreciated. Also is there any software that will create a schema from an XML file?
January 17, 2015 at 3:55 pm
In Management Studio right click the database name, chose tasks and then Import Data ...
this will open a wizard that will walk you through the import process
Cheers,
Iulian
January 17, 2015 at 4:41 pm
Thanks that looks useful however there doesn't seem to be an option to import XML files?
January 18, 2015 at 2:36 am
One option that I often use for ad-hoc imports of XML if you can get the xml files onto the SQL server is this method:
declare @xml xml
SELECT @xml = BulkColumn
FROM OPENROWSET (BULK 'c:\temp\myxmlfile.xml', SINGLE_CLOB) x
another option which I use if I need a regular import of XML files into SQL is by using a FILETABLE as a means to make the data available to SQL. i.e. drop the xml files into the file share exposed by the FILETABLE then you can access that table (files) from within SQL.
January 18, 2015 at 2:47 am
Also is there any software that will create a schema from an XML file?
You can use visual studio to create a schema from an xml document, and generally it will do a good job, but you'll have to spend a little time afterwards refining it to get it 100% so that it does correctly define the xml with regards to the data types, occurrences and restrictions etc.
January 18, 2015 at 7:16 am
Thanks for this however I have VS Express and creating an XML schema from an XML document is a feature not included.
January 18, 2015 at 7:28 am
ok. i just did a quick google and there were a number of free online xsd from xml generators on the first page. not tried any myself so can't comment on how good the resultant schema is. try a couple out and see what you get back and what the differences are. if your xml structure isn't too complicated then I'd imagine most would do a fairly ok job
January 20, 2015 at 2:14 am
Also is there any software that will create a schema from an XML file?
Apart from the previous suggestions and professional XML editing tools, if you have Microsoft InfoPath as part of Microsoft Office, InfoPath can be used to generate (infer) XML schemas from XML sample documents (with some limitations). You can also make edits to the data structure within InfoPath. This might produce a "good enough" approximation schema for your needs.
Viewing 8 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply