Solved

Query an XML file

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

A basic question.. “What is the Garbage Collector?” The usual answer given back: “Garbage collector is a background thread run by the CLR for freeing up the memory space used by the objects which are no longer used by the program.” I wondered …
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

762 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now