eclipselink moxy xpath - selecting all child elements of the current node or all elements in a document with a particular name

情到浓时终转凉″ 提交于 2019-12-08 08:32:39

问题


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).


回答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:

  • https://bugs.eclipse.org/bugs/enter_bug.cgi?product=EclipseLink

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

  • http://blog.bdoughan.com/2010/07/xpath-based-mapping.html
  • 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


来源:https://stackoverflow.com/questions/9582249/eclipselink-moxy-xpath-selecting-all-child-elements-of-the-current-node-or-all

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!