Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MarkLogic to Java & Back Solution

I need to query XML out of a MarkLogic server and marshal it into Java objects. What is a good way to go about this? Specifically:

  1. Does using MarkLogic have any impact on the XML technology stack? (i.e. is there something about MarkLogic that leads to a different approach to searching for, reading and writing XML snippets?)
  2. Should I process the XML myself using one of the XML APIs or is there a simpler way?
  3. Is it worth using JAXB for this?

Someone asked a good question of why I am using Java. I am using Java/Java EE because I am strongest in that language. This is a one man project and I don't want to get stuck anywhere. The project is to develop web service APIs and data processing and transformation (CSV to XML) functionality. Java/Java EE can do this well and do it elegantly.

like image 917
Guido Anselmi Avatar asked Oct 06 '11 00:10

Guido Anselmi


3 Answers

Note: I'm the EclipseLink JAXB (MOXy) lead, and a member of the JAXB 2 (JSR-222) expert group.

Does using MarkLogic have any impact on the XML technology stack? (i.e. is there something about MarkLogic that leads to a different approach to searching for, reading and writing XML snippets?)

Potentially. Some object-to-XML libraries support a larger variety of documents than other ones do. MOXy leverages XPath based mappings that allows it to handle a wider variety of documents. Below are some examples:

  • http://blog.bdoughan.com/2010/09/xpath-based-mapping-geocode-example.html
  • http://blog.bdoughan.com/2011/03/map-to-element-based-on-attribute-value.html

Should I process the XML myself using one of the XML APIs or is there a simpler way?

Using a framework is generally easier. Java SE offers may standard libraries for processing XML: JAXB (javax.xml.bind), XPath (javax.xml.xpath), DOM, SAX, StAX. Since these standards there are also other implementations (i.e. MOXy and Apache JaxMe implement JAXB).

  • http://blog.bdoughan.com/2011/05/specifying-eclipselink-moxy-as-your.html

Is it worth using JAXB for this?

Yes.

like image 75
bdoughan Avatar answered Nov 15 '22 12:11

bdoughan


There are a number of XML-> Java object marshall-ing libraries. I think you might want to look for an answer to this question by searching for generic Java XML marshalling/unmarshalling questions like this one:

Java Binding Vs Manually Defining Classes

Your use case is still not perfectly clear although the title edit helps - If you're looking for Java connectivity, you might also want to look at http://developer.marklogic.com/code/mljam which allows you to execute Java code from within MarkLogic XQuery.

like image 39
Eric Bloch Avatar answered Nov 15 '22 10:11

Eric Bloch


XQSync uses XStream for this. As I understand it, JAXB is more powerful - but also more complex.

like image 26
mblakele Avatar answered Nov 15 '22 11:11

mblakele