XQuery Example



Contents:

1) What is it?
2) Download
3) How it works?
4) Screenshots
5) Support
6) User's Comments



What is it?

It is a open-source example of how to implement XQuery using 'The SAXON XSLT and XQuery Processor'. To make this example more interesting and useful to test, I made a web interface usign REST servlets approach. However the main logic is basic and can be find in org.jdamico.xml package at Utils class:

InputStream is = new ByteArrayInputStream(xml.getBytes());
final Configuration config = new Configuration();
final StaticQueryContext sqc = new StaticQueryContext(config);
final XQueryExpression exp = sqc.compileQuery(xquery);
Properties props = new Properties();
props.setProperty(OutputKeys.OMIT_XML_DECLARATION, "no");
props.setProperty(OutputKeys.INDENT, "yes");
final DynamicQueryContext dynamicContext = new DynamicQueryContext(config);
dynamicContext.setContextItem(config.buildDocument(new StreamSource(is)));
DOMResult result = new DOMResult();
exp.run(dynamicContext, result, new Properties());
ByteArrayOutputStream bos = new ByteArrayOutputStream();
Transformer identity = TransformerFactory.newInstance().newTransformer();
identity.transform(new DOMSource(result.getNode()), new StreamResult(bos));


Feel free to use. Remember that in order to work you will need saxon library into your classpath. You can find it in WEB-INF/lib folder.

By the way, I've used Eclipse 3.2 with WebTools to code it, running over JDK 1.5.

Download:

You can choose 2 ways of download: Eclipse project source-files or .War file. This small app was tested in Apache Tomcat 5.5, Websphere Application Server 6.1 and should work in any Application Server or Servlet Container.

How it works?

Simple. 3 steps:

1. Add a XML file
2. Write a XQuery to be applied over XML file added
3. Process and see the XQuery XML result

Screenshots:

Screen 1

Screen 2

Screen 3

Support:

To receive support or to inform bugs send an email to Jose Damico (My Email)

User's Comments:



Name:
Email:
Comment:
 



Go back to jd.comment
Valid XHTML 1.0! hacker emblem