问题描述
我在jaxb类中为moxy定义了这个xpath
i have this xpath defined for moxy in a jaxb class
@XmlPath( child :: * / REG)
public List条目;
@XmlPath("child::*/REG")public List entries;
,但不会正确解组xml文档。
but it won't unmarshal the xml document correctly. the List variable called entries is empty.
我也尝试过
@XmlPath( * / REG )
公共列表条目;
@XmlPath("*/REG")public List entries;
我也尝试过
@XmlPath( / / REG)
公共列表条目;
@XmlPath("//REG")public List entries;
没有喜悦
但如果我这样做
@XmlPath( BANKGIRO / REG)
公开列表项;
@XmlPath("BANKGIRO/REG")public List entries;
这很好,列表也不错
我还没有看过源代码,但我猜想还不支持这种类型的xpath。我检查了我在xpath验证程序中的所有xpath的完整性,并且上面的所有xpath都很好(所有xpath对我所处的上下文节点均有效)。
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).
推荐答案
当前不支持XPath,例如: @XmlPath( child :: * / REG)
。我们一直致力于支持XPath语句,该语句提供了用于编组和解组的足够信息。例如,很明显 @XmlPath( child :: * / REG)
在读取时意味着什么,但是在将该对象写回XML或JSON时存在歧义。如果您对这种支持感兴趣,请输入增强请求:
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确实支持XPath,
MOXy does support XPath like:
- @XmlPath(。)/ /映射到自身节点,在将两个对象映射到同一元素时很有用
- @XmlPath( @ foo)//映射到属性
- @ XmlPath( foo)//映射到元素
- @XmlPath( foo [2])//映射到
- 的第二次出现@XmlPath( foo [@ bar ='Hello World']))//映射到带有bar属性且值为 Hello World的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 xpath-选择当前节点的所有子元素或具有特定名称的文档中的所有元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!