我们正在处理一个相当复杂的 XML 模式 (HR-XML),并希望使用基于 xpath 的映射方法来解组到我们本地定义的域对象。我们尝试了 Simple 但遇到了问题。我们最近尝试了 MOXy,运气好一点,但遇到了谓词支持问题。我正在尝试确认 MOXy 是否支持我认为我需要使用的谓词。我需要做的是根据兄弟元素的值检索一个元素的值。
当它被执行时,我得到空值,就像它没有正确选择一样。有没有人做过类似的?也许还有另一个问题?
示例 XML:
<person>
<communication>
<address>
<street>101 First St.</street>
<city>Whoville</city>
<state>CA</state>
</address>
</communication>
<communication>
<channelcode>email</channelcode>
<uri>johndoe@some.com</uri>
</communication>
<communication>
<channelcode>telephone</channelcode>
<usecode>mobile</usecode>
<dialnumber>555-555-5555</dialnumber>
</communication>
</person>
示例对象:
public class Person
{
private String email;
private Address homeAddress;
private String homePhone;
...
xml-bindings.xml 片段示例:
<java-types>
<java-type name="Person">
<xml-root-element name="person">
<java-attributes>
<xml-element java-attribute="email" xml-path="communication/uri[../channelcode/text()='email']/text()" />
<xml-element java-attribute="homePhone" xml-path="communication[channelcode/text()='telephone']/dialnumber/text()" />
<xml-element java-attribute="homeAddress" xml-path="communication/Address" />
</java-attributes>
</java-type>
...