本文介绍了EclipseLink MOXy @XmlPath支持axis / parent的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下任何XPath表达式是否可以接受?使用eclipselink的2.3.1版本

Are any of the following XPath expressions acceptable? Using version 2.3.1 of eclipselink

@XmlPath("../header/@type")
@XmlPath("/root/header/@type")
@XmlPath("parent::*/header/@type")

基本上这是在XML文档中重复的类( / root / tag ),如果不清楚我会详细说明。

Basically this is in a class which repeats within the XML document (/root/tag), if that isn't clear I'll elaborate.

我正试图遍历树而不是向下。我的其他 @XmlPath 注释工作正常。

I'm trying to traverse up the tree rather than down. My other @XmlPath annotations are working fine.

推荐答案

目前不支持axis / parent。如果您对此类支持感兴趣,请输入增强请求:

EclipseLink JAXB (MOXy) does currently not support axes/parent. If you are interested in this kind of support please enter an enhancement request:



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

它确实支持XPath:

It does support XPath like:


  • @XmlPath(。)/ /映射到自身节点,在将两个对象映射到同一元素时很有用

  • @XmlPath(@ foo)//映射到属性

  • @ XmlPath(foo)//映射到元素

  • @XmlPath(foo [2])//映射到第二次出现

  • @XmlPath(foo [@ bar ='Hello World'])//使用值为Hello World的bar属性映射到foo元素

  • @XmlPath(ns1:foo / ns2:@bar)//映射到命名空间限定节点

  • @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

更多信息





  • 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

这篇关于EclipseLink MOXy @XmlPath支持axis / parent的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-01 08:01