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?
Is there any framework for querying XML SQL Syntax, I seriously tire of iterating through node lists.
XQuery and XPath... XQuery is more what you are looking for if a SQL structure is desirable.
.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.
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.
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.
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.