Solved

Query an XML file

Posted on 2013-01-11
2
210 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

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

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

It seems a simple enough task, yet I see repeated questions asking how to do it: how to pass data between two forms. In this article, I will show you the different mechanisms available for you to do just that. This article is directed towards the .N…
The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

829 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