As my research pointed out XMLDB was a bit painfull to use as most xmldb implementations had quite specific API's to accomplish the same result. I instead turned my focus to the newer XQJ API which offers a JDBC alike approach to using XQuery.
Today I wrote a first draft version of an XQJGenerator accompanied from 2 basic unit tests. Although you have to be carefull that not all XQueries can be ported from XMLDB API to XQJ i managed to get the results extracted the way I wanted to.
XQJGenerator.java
XQJGeneratorTest.java
xquery1.xquery
demoboards1.xquery
test-application-context.xml
xquery1.xquery output
demoboards1.xquery output
If you're interested in functional programming, you might also want to checkout my second blog which i'm actively working on!!
Tuesday, July 5, 2011
Friday, July 1, 2011
Comparing usage of XMLDB Services
As I want to be able to use all XMLDB API services from within Cocoon a first task is comparing in what aspect usage differs accross 'Service' and 'XMLDB'.
Any good observer can see that it's possible to abstract this a bit further:
Using XpathQueryService with BaseX:
Using XQueryService with Sedna:
Any good observer can see that it's possible to abstract this a bit further:
Using XpathQueryService with BaseX:
Using XQueryService with Sedna:
Cocoon 3.0 and XML DB API
Yesterday evening i checked out the latest sources from Cocoon3.0 and started diving into the source code to get a feeling of how things work in this new version. As Jeroen Reijn already pointed out in this article it only takes you half an hour to be up and running building your own custom pipeline.
The company where i'm currently working at recently started using an XML DB (instead of storing files on a filesystem) based upon my advice. We already were using a custom XQueryGenerator for Cocoon2.2 but as a little exercise I quickly hacked some code together based upon Cocoon3. The actual code of the XQueryGenerator is not yet worthy to be shared but I just wanted to share the results of 2 little unit tests.
demoboard module:
demoboards1.xquery:
demoboards2.xquery:
Both Xqueries should return the same result which they do.
The company where i'm currently working at recently started using an XML DB (instead of storing files on a filesystem) based upon my advice. We already were using a custom XQueryGenerator for Cocoon2.2 but as a little exercise I quickly hacked some code together based upon Cocoon3. The actual code of the XQueryGenerator is not yet worthy to be shared but I just wanted to share the results of 2 little unit tests.
demoboard module:
demoboards1.xquery:
demoboards2.xquery:
Both Xqueries should return the same result which they do.
Tuesday, June 28, 2011
Finished some restyling of this blog
Ok.. I just received news of Google's +1 button which is kinda cool to get noticed so I decided to hack it in. Because i again played around with the template designer of my blog my previous customizations got lost. Nothing to worry really, only SyntaxHighLighter was not working anymore and my code snippets magically vanished. So I decided to switch to using the latest and greatest version of SyntaxHighLighter and use the autoloader which was a new feature. I also am using the hosted version of the css and js files which is easier.
One side note: I had to make sure syntaxhighlighter got bootstrapped only after the dom was loaded. So I used YUI3's onDomReady event to call a bootstrapSyntaxHighLighter function i wrote.
One side note: I had to make sure syntaxhighlighter got bootstrapped only after the dom was loaded. So I used YUI3's onDomReady event to call a bootstrapSyntaxHighLighter function i wrote.
Tuesday, June 14, 2011
Mimicking the Switch Expression in XQuery1.0
Here follows a little trick I picked up. Sometimes you want just like in many other programming languages to handle several use cases depending on a switch expression. This is not possible for XQuery1.0 by default but that does not mean you can't mimic it using the typeswitch expression ;-)
Output:
Output:
Labels:
xquery
Complex Grouping with Xquery ...the general pattern
Testdata:
The idea is that we group all items so we get combinations of chapter with resp. paragraphs. However, some paragraphs don't have a parent (chapter). In this case those paragraphs should be handled first.
Expected output:
Well, here is kind of a generic solution (read solution pattern). You need 1 function that extracts the groupingkey from an item. The getGroupingKeys function just takes the distinct values of all grouping keys. So when you have the groupingkeys, you can determine the items belonging to each group using this predicate [local:getGroupingKey(.) = $grouping_key]. Next you handle the items for each group the way you want.
The idea is that we group all items so we get combinations of chapter with resp. paragraphs. However, some paragraphs don't have a parent (chapter). In this case those paragraphs should be handled first.
Expected output:
Well, here is kind of a generic solution (read solution pattern). You need 1 function that extracts the groupingkey from an item. The getGroupingKeys function just takes the distinct values of all grouping keys. So when you have the groupingkeys, you can determine the items belonging to each group using this predicate [local:getGroupingKey(.) = $grouping_key]. Next you handle the items for each group the way you want.
Labels:
xquery
Generic Join function (XSLT/ Xquery)
In case you need a very high level join function for a sequence of items, I just wrote one which works very nicely.
Thursday, March 24, 2011
Portable GIT for windows
I was facing issues setting up my git account the other day because my default user.home was pointing to a H: drive on which I only had read rights. Really helpfull if you ask me. Anyway... i found this nice article of how to create a portable GIT config.
Labels:
Github
Wednesday, March 16, 2011
Building JSON webservices with Sedna, XQuery, Apache Cocoon and XSLT2.0 (part 2)
Next I needed to come up with a generic xslt that would transform the Javascript-ish xml representation to JSON.
So after some struggling i ended up with following solution:
So with input below I would get
output below:
Please pay attention to the fact that I even took care of supporting formatting date(time)s and numbers with my implementation.
Another more complex example
will result in
So after some struggling i ended up with following solution:
So with input below I would get
output below:
Please pay attention to the fact that I even took care of supporting formatting date(time)s and numbers with my implementation.
Another more complex example
will result in
Labels:
javascript,
JSON,
XML,
xslt2.0
Building JSON webservices with Sedna, XQuery, Apache Cocoon and XSLT2.0 (part 1)
Goal of project: Easily allow webapps within our intranet to fetch data from XML DB (Sedna) in JSON format.
First I wanted to come up with a XML schema to represent JSON data. So after some trial and error I ended up with following schema:
Some concrete examples of above schema:
More info available at Part 2
First I wanted to come up with a XML schema to represent JSON data. So after some trial and error I ended up with following schema:
Some concrete examples of above schema:
More info available at Part 2
Labels:
javascript,
JSON,
XSD
Subscribe to:
Posts (Atom)