簡體   English   中英

Smooks-如何將options元素從xml映射到Java

[英]Smooks - How to map choices element from xml to java

可能在煙霧(版本1.5.1)中將兩個選擇元素中的一個生成的元素映射到java字段?

例:

xsd文件:

<complexType name="timeType">
  <sequence>
    <choice minOccurs="1" maxOccurs="1">
    <element name="time"  minOccurs="0" maxOccurs="1">
      <complexType>
        <attribute name="v" type="dateTime"/>
      </complexType>
    </element>
    <element name="time2"  minOccurs="0" maxOccurs="1">
      <complexType>
        <attribute name="v" type="dateTime"/>
      </complexType>
    </element>
    </choice>
</complexType>

a)xml file1:

<parent>
  <time v="2001-12-31T12:00:00"/>  
</parent>

b)xml file2:

<parent> 
  <time2 v="2002-12-31T12:00:00"/>
</parent>

煙霧映射

<jb:bean beanId="timeRef" class="someClass" createOnElement="parent">
  <!--  only if is generated (present) time element map this time element-->
  <jb:value property="fromHour" data="time/@v" decoder="DateTime" />

  <!-- only if is generated (present) time2 element map time2 element -->
  <jb:value property="fromHour" data="time2/@v" decoder="DateTime" />
</jb:bean>

我如何告訴騙子,我只想保存一個生成的元素? 謝謝

我的解決方案:

<jb:bean beanId="parentBeanId" class="parentMapClass" createOnElement="parentElement">
      ...
      <jb:wiring property="property" beanIdRef="timeRef" />
      <jb:wiring property="property" beanIdRef="timeIntervalRef" />
      ...
</jb:bean>

<jb:bean beanId="timeRef" class="someClass" createOnElement="parentElement/time">
      <jb:value property="fromHour" data="time/@v" decoder="DateTime" />
      <jb:value property="toHour" data="time/@v" decoder="DateTime" />
</jb:bean>

   <jb:bean beanId="timeIntervalRef" class="someClass" createOnElement="parentElement/timeInterval">
      <jb:value property="fromHour" data="timeInterval/@v" decoder="TimeIntervalFrom" />
      <jb:value property="toHour" data="timeInterval/@v" decoder="TimeIntervalTo" />
   </jb:bean>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM