Solved

Query an XML file

Posted on 2013-01-11
2
208 Views
Last Modified: 2013-01-16
I need to query an XML file. I thought about loading it to a dataset. But then I am not able to apply SQL on it? How can I query the dataset that comes from an XML file stored on disk?
0
Comment
Question by:Frans_Truyens
2 Comments
 
LVL 9

Accepted Solution

by:
sognoct earned 500 total points
ID: 38768845
once loaded the xml into dataset in framework 4.0 you can use LINQ for doing queries :

example here :
http://msdn.microsoft.com/en-us/library/bb386910.aspx

in framework 2.0 instead can use datatable.select method
example here :
http://msdn.microsoft.com/en-us/library/det4aw50.aspx

or in framework 2.0 can use dataview rowfilter (really fast) for filtering data inside a datatable
0
 
LVL 13

Expert Comment

by:agarwalrahul
ID: 38773353
Try This Code:
  CREATE TABLE XmlImportTest
    (
        xmlFileName VARCHAR(300),
        xml_data xml
    )
    GO

    DECLARE @xmlFileName VARCHAR(300)
    SELECT  @xmlFileName = 'C:\xmlPath.xml'
    -- dynamic sql is just so we can use @xmlFileName variable in OPENROWSET
    EXEC('
    INSERT INTO XmlImportTest(xmlFileName, xml_data)

    SELECT ''' + @xmlFileName + ''', xmlData
    FROM
    (
        SELECT  *
        FROM    OPENROWSET (BULK ''' + @xmlFileName + ''' , SINGLE_BLOB) AS XMLDATA
    ) AS FileImport (XMLDATA)
    ')
    GO
    SELECT * FROM XmlImportTest

    DROP TABLE XmlImportTest

Reference:
http://stackoverflow.com/questions/11631352/import-xml-file-into-sql-server-table
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question