2013-01-16 94 views
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> 
    ... 

回答

0

目前EclipseLink JAXB (MOXy)要求謂詞檢查的值XML屬性。這意味着,如果你有以下的XML:

<?xml version="1.0" encoding="UTF-8"?> 
<person> 
    <communication channelcode="address"> 
     <address> 
     <city>Whoville</city> 
     <state>CA</state> 
     <street>101 First St.</street> 
     </address> 
    </communication> 
    <communication channelcode="email"> 
     <uri>[email protected]</uri> 
    </communication> 
    <communication channelcode="telephone"> 
     <dialnumber>555-555-5555</dialnumber> 
    </communication> 
</person> 

然後,你可以將其與以下地圖:

<?xml version="1.0"?> 
<xml-bindings 
    xmlns="http://www.eclipse.org/eclipselink/xsds/persistence/oxm" 
    package-name="forum14368563" 
    xml-accessor-type="FIELD"> 
    <java-types> 
     <java-type name="Person"> 
      <xml-root-element/> 
      <xml-type prop-order="homeAddress email homePhone"/> 
      <java-attributes> 
       <xml-element java-attribute="homeAddress" xml-path="communication[@channelcode='address']/address"/> 
       <xml-element java-attribute="email" xml-path="communication[@channelcode='email']/uri/text()"/> 
       <xml-element java-attribute="homePhone" name="communication[@channelcode='telephone']/dialnumber/text()"/> 
      </java-attributes> 
     </java-type> 
    </java-types> 
</xml-bindings> 
+0

這仍然是真的嗎?我和XPath的通訊[not(channelcode)]/dialnumber/text()'有類似的問題,即查找沒有兒子的節點。 – selotape