2013-05-10 2 views
1

можно в smooks (версия 1.5.1) отображать только один сгенерированный элемент из двух элементов выбора в поле java?Smooks - Как отобразить элемент выбора из xml в 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> 

а) XML файл1:

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

б) XML файл2:

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

smooks отображение

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

Как я могу сказать, что хочу сохранить только один сгенерированный элемент? Благодаря

ответ

1

Мое решение:

<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> 
Смежные вопросы