1

i have this xpath defined for moxy in a jaxb class

@XmlPath("child::*/REG") public List entries;

but it won't unmarshal the xml document correctly. the List variable called entries is empty.

i've also tried

@XmlPath("*/REG") public List entries;

i've also tried

@XmlPath("//REG") public List entries;

without joy

but if i do

@XmlPath("BANKGIRO/REG") public List entries;

it's fine and the list is populated.

I haven't looked through the source yet but I'm guessing this type of xpath is not supported yet. I checked all my xpath in an xpath verifier for sanity and all the xpath above is fine (all the xpath is valid for the context node i'm positioned at).

iou1
  • 43
  • 7

1 Answers1

1

EclipseLink JAXB (MOXy) does currently not support an XPath like: @XmlPath("child::*/REG"). Our focus has been on supporting XPath statements that provide enough information for marshalling as well as unmarshalling. For example it is clear what @XmlPath("child::*/REG") means on a read, but is ambiguous in terms when writing that object back to XML or JSON. If you are interested in this kind of support please enter an enhancement request:

MOXy does support XPath like:

  • @XmlPath(".") // Map to self node, useful when mapping two objects to same element
  • @XmlPath("@foo") // Map to attribute
  • @XmlPath("foo") // Map to element
  • @XmlPath("foo[2]") // Map to 2nd occurence of
  • @XmlPath("foo[@bar='Hello World']") // Map to foo element with bar attribute with value "Hello World"
  • @XmlPath("ns1:foo/ns2:@bar") // Map to namespace qualified nodes

For More Information

bdoughan
  • 147,609
  • 23
  • 300
  • 400
  • I thought it would be because mapping back to xml would be ambiguous but a simple XmlElement(name="blah") (use xpath when unmarshalling, and XmlElement when marshalling) would seem to me to be a way out. however, I am aware that the ramifications of my solution may mean that it is not as easy as it seems. otherwise great product. i shall raise the request – iou1 Mar 06 '12 at 16:12
  • I'm happy to hear you're enjoying MOXy. This is definitely an interesting use case. I would appreciate any thoughts you have in terms of what the metadata might look like. – bdoughan Mar 06 '12 at 16:20
  • i've raised the change request already, at https://bugs.eclipse.org/bugs/show_bug.cgi?id=373400. hope i can help. just so others are aware the | operator also isn't supported. – iou1 Mar 06 '12 at 17:07