Query data (SELECT * FROM table) from XML File

F

Frank Uray

Hi all

On SQL Server tables I use SqlDataReader to query data
like "SELECT * FROM table".

Is there something similar for XML Files ?
I want to use SQL Syntax like "SELECT * FROM table" on
a XML file. After query I want to get something like SqlDataReader
based on Query to loop.
I do not want to use a DataSet. It should be more like streaming
and not loading the whole set into Memory.

Any ideas ?
Thanks for any comments.

Best regards
Frank
 
J

Jon Skeet [C# MVP]

On SQL Server tables I use SqlDataReader to query data
like "SELECT * FROM table".

Is there something similar for XML Files ?
I want to use SQL Syntax like "SELECT * FROM table" on
a XML file. After query I want to get something like SqlDataReader
based on Query to loop.
I do not want to use a DataSet. It should be more like streaming
and not loading the whole set into Memory.

If you use LINQ to XML you can use SQL-like syntax (though not SQL
itself) and get compile-time checking too.

I don't know if LINQ to XML supports streaming. This post:
http://blogs.msdn.com/xmlteam/archive/2007/03/05/streaming-with-linq-to-xml-part-1.aspx
suggests that it doesn't, for input. You may be able to search for
some workarounds though.

Of course, using LINQ to XML to start with assumes you're able to
use .NET 3.5 - is that likely to be a problem for you?

Jon
 
M

Misbah Arefin

You could use LINQ or XPath & XmlReader but I don’t think there is any SQL
over XML provider
 
C

Cor Ligthert [MVP]

Frank,

In C# there is not a Linq to XML solution, however what is wrong with the
dataset.

You get mostly an XML file in a dataset with

ds.readXML(path).

The dataset is a very optimized OO collection so I am very interested what
will be the problem?

Every other method will probably consume more memory and at least more
resources.

Cor
 
M

Marc Gravell

You get mostly an XML file in a dataset with
ds.readXML(path).

The dataset is a very optimized OO collection so I am very interested what
will be the problem?

Well, it doesn't work so well with huge volumes...
Every other method will probably consume more memory and at least more
resources.

Well, except XmlReader... I do have a streaming (yield iterator)
XmlReader in my toolkit, but it is quite lengthy and has some
limitations - for example it assumes that all the "fields" are direct
descendents (either elements or attributes) of the element you are
reading, and it takes no account of hierarchy (it just uses
MoveToFollowing to get the next candidate record). Maybe I'll write it
up some time and put it somewhere more public...

Marc
 
F

Frank Uray

Hi Cor

Thanks for your answer.

I have a application that has online connection
to SQL Server (SqlDataReader ...).
In this application, as a SQL Engineer, I use SQL Syntax.

First is I want SQL Server to select subsets of data,
I dont want to load it all into local Application Memory.
But the real problem is, I want to change application to
be able to run in a offline modus using XML files.

If I would be able to somehow create SqlDataReader from
DataSet and/or XML File, I dont have to change a lot within
the application. Data Syncronizing would not be a big deal.

So, I guess there is no solution to do this and I
have to change the whole application to use DataSet.
Than I am able to use both, online and offline.

Thanks anyway
Frank
 
M

Marc Gravell

What are in your idea huge volumes, that is very subjective you know?

Oh absolutely! That is exacatly why I used a vague term like "huge".
Especially if we include some behemoths on x64 with tons of memory.
As we both know, it depends on too many factors to even go into - but
either way, a streaming API will scale effortlessly, where-as with an
in-memory answer we need to ask "how big"?

But I also agree that streaming APIs aren't necessarily the easiest
from an OO point of view, unless you are just doing aggregates etc.

Marc
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top