How can I execute the following XQuery on an XML file using javax.xml.xpath?
for $com in //RepoStatistics/Commits/Commit
return
for $file in $com//File
return element tuple {
element path {
string($file/Path)
},
element action {
string($file/@action)
},
element date {
string($com/@date)
},
element developer {
string($com/@author)
},
element locAdd{
if (not(empty($file/LocAdd)))
then string($file/LocAdd)
else 0
},
element locRem{
if (not(empty($file/LocRem)))
then string($file/LocRem)
else 0
}
}
Excuse me if the question is stupid, but I am a very beginner.
XPath is a subset of XQuery. The JDK comes with a built-in implementation of XPath, which can be used via the javax.xml.path API (the same API can also be used for other XPath implementations, such as Saxon and Jaxen). There is no XQuery engine delivered with the JDK, but a number are available from third parties; there are some lists of products on the W3C XQuery page, but an easy one to try out is Saxon. There is a “standard” API for accessing XQuery from Java called XQJ (package javax.xml.xquery), which Saxon and most other Java-based XQuery implementations support.
(Saxon also has another interface called s9api, designed partly to get around the limitations of XQJ, and partly to provide a single integrated API that handles XSLT, XPath, XQuery, and XML Schema in a coherent way, allowing you to build applications that use all these technologies together.)