2
我們正在處理一個相當複雜的XML模式(HR-XML),並希望使用基於xpath的映射方法對我們本地定義的域對象進行解組。我們嘗試了Simple,但遇到了問題。我們最近嘗試了MOXy,但運氣稍好一些,但卻遇到了謂詞支持問題。我試圖確認MOXy是否支持我認爲我需要使用的謂詞。我需要做的是根據兄弟元素的值檢索一個元素的值。JAXB/MOXy XPath謂詞支持
當這個被執行時,我得到空值,因爲它沒有正確選擇。有人做過類似的事嗎?也許還有另一個問題?
例XML:
<person>
<communication>
<address>
<street>101 First St.</street>
<city>Whoville</city>
<state>CA</state>
</address>
</communication>
<communication>
<channelcode>email</channelcode>
<uri>[email protected]</uri>
</communication>
<communication>
<channelcode>telephone</channelcode>
<usecode>mobile</usecode>
<dialnumber>555-555-5555</dialnumber>
</communication>
</person>
實施例的OBJ:
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>
...
這仍然是真的嗎?我和XPath的通訊[not(channelcode)]/dialnumber/text()'有類似的問題,即查找沒有兒子的節點。 – selotape