Martin Probst complaints about overly complex XML-APIs and recommends the use of XQuery as a language that can be used to work with XML data programatically, that does not suck.
In most cases XQuery is more than people need in their applications. It is very powerful and you can build complex applications with XQuery, but there will be no one to write a complete CRM or ERP using XQuery. Instead they are going to embed XQuery in their existing Java, C++, C#, whatever-code. An XQuery-API that allows you to seamlessly access parts of one or more XML documents might be a great helper.
In fact XPath 2.0 might be sufficient for most applications. If you can do the for-loop in your favorite programming language, why should you bother to learn the syntax of FLOWR-queries. If you need the contents of a special element /foo/bar\[@what='ever'] should be enough. This makes XPath with a good API an ideal replacement of DOM.
/foo/bar[@what='ever'] is just easier to read, write and understand than
Document document = ...
foreach (Element e1 : document.getChildElements()) {
if (e1.getLocalName().equals("foo")) {
foreach (Element e2 : e1.getChildElements()) {
if (e2.getLocalName().equals("foo")) {
if ("ever".equals(e2.getAttribute("what"))) {
//do something
}
}
}
}
}
which is not real DOM, but a much simplified pseudo-code-version.
But I like SAX much more than DOM. It is faster, has reduced memory-consumption and I you have to think some seconds before you start to work, which leads to code that looks as if someone has thought about the problem before starting to write something.
It is obvious that a tree-based approach that is used by XPath cannot be used to wrap a SAX-like API. Perhaps STXPath, which is used for Streaming Transformations for XML (STX) might be a solution. This seems the be exacly the problem David Megginson already thinks of .