MOXy JAXB dynamic bindings with XPath

318 Views Asked by At

I've been finding the MOXy JAXB implementation wonderful due to the @XmlPath annotation. Basically I've got a large XML schema from which I actually require 20/30 values via XPath. This is very slow using actual XPath (I'm doing this highly threaded at real time on a large pipe of data) so MOXy is perfect for this. This does however mean coding is required to modify which XPaths I extract when parsing.

I know MOXy does dynamic bindings but I couldn't find any information on whether I can replicate the same XPath functionality using these bindings. Anyone know if this is possible or whether I need to stick with annotated classes?

For example, I might have a couple of classes like this:

public class Request {

  @XmlPath("a/b/c/@id")
  String id;

  @XmlPath("a/b/c/listitems")
  Listitem[] listitems;
  //getters, setters, etc...

}

public class Listitem {

  @XmlPath("x/y/z/@id")
  String id;

  @XmlPath("x/y/z/text()")
  String text;
  //getters, setters, etc...

}

Ideally I'd like users of my system who know nothing about Java but do know XML and XPath to configure those XPaths in a config file, and be able to extract a new field, x/y/z/@newAttribute for example, without having to change any code at all.

At a push I can explain how to edit the Java versions and add classes etc... but if there is a way to use XPaths within a configuration file instead to create a dynamic map of properties then that would be amazingly useful, hence the question.

0

There are 0 best solutions below