views:

431

answers:

8

Is there any framework for querying XML SQL Syntax, I seriously tire of iterating through node lists.


Or is this just wishful thinking (if not idiotic) and certainly not possible since XML isn't a relational database?

+12  A: 

XQuery and XPath... XQuery is more what you are looking for if a SQL structure is desirable.

dacracot
Cool, I've been using XPath because it's implemented in PHP's simpleXML, I guess I just missed XQuery.
Peter Turner
Xquery implements XPath, however it is the work of the devil.
Tarski
+2  A: 

.Net Framework provides LINQ to do this or you can use the .Net System.Data namespace to load data from XML files.

You can even create queries that have joins among the tables, etc.

For example, System.Data.DataTable provides a ReadXml() method.

Craig Eddy
+1  A: 

You could try LINQ to XML, but it's not language agnostic.

chris
Nor is it in SQL I believe?
Meff
The LINQ part is .net, so you can use any language with a CLR compiler
chris
+3  A: 

http://en.wikipedia.org/wiki/Xquery

Andy Brice
A: 

SQL Server 2005 supports XML DML on it's native xml data type.

Constantin
+1  A: 

XQuery is a functional language that is closest to SQL. XPath is a notation for locating a node within the document that is used as part of XSLT and XQuery.

XML databases such as MarkLogic serve as XQuery engines for XML data, much as relational databases serve as SQL engines for relational data.

MattMcKnight
Sql Server and Oracle support XQuery too.
tuinstoel
A: 

XQuery is certainly the way forward. This is what is used by XML databases like eXist and MarkLogic.

In the Java world there are several solutions for running XQuery on flat files, most notably Saxon

For .NET, there is not so much available. Microsoft did have an XQuery library, although this was pulled from .NET 2 and has never resurfaced. XQSharp is a native .NET alternative, although currently only a command line version has been released.

Oliver Hallam
+1  A: 

That depends on the problem you are solving. If XML file is pretty large, sometimes it's a necessity to use something like SAX parsers to traverse the file node by node, or you will get OutOfMemoryException or will run out even of virtual memory on your computer.

But, if the expected size of XML file is relatively small, you can simply use something like Linq, also see my answer - here I tried to explain, how to make traversing through nodes much easier with constructions like yield return.

SPIRiT_1984
I just ran into a similar issue, I've got MSXML6 reading in 300 meg XML files and using upwards of a Gig of RAM. Fortunately this worked with win2k and I only had a few problems with VMs with extremely small page files. I think Yield return would work, but unfortunately I'm a Delphi programmer and SOL for all .NET hotness.
Peter Turner