2013-01-16 2 views
2

우리는 다소 복잡한 XML 스키마 (HR-XML)를 사용하고 xpath 기반 매핑 방법을 사용하여 로컬로 정의 된 도메인 객체에 언 마샬링하려고합니다. 우리는 Simple을 시도했지만 문제가 발생했습니다. 우리는 최근 MOXy를 조금 더 나은 방법으로 시도했지만 술어 지원에 문제가 발생했습니다. 나는 MOXy가 내가 필요로하는 술어를 지원하는지 확인하려고 노력하고있다. 형제 요소의 값을 기반으로 한 요소의 값을 검색해야합니다.JAXB/MOXy XPath 술어 지원

이것이 실행될 때 올바르게 선택되지 않은 것처럼 null이 나타납니다. 아무도 비슷한 짓하지 않았습니까? 어쩌면 또 다른 문제가 있을까요?

예 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 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

이 여전히 사실인가요 다음과 같은 XML이 있다면 이는? 나는 XPath의 통신 [채널 코드가 아님]/dialnumber/text()와 비슷한 문제, 즉 아들이없는 노드를 찾고있었습니다. – selotape