Announcement Announcement Module
Collapse
No announcement yet.
Unable to write expectec XML file with StaxEventItemWriter Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Unable to write expectec XML file with StaxEventItemWriter

    Hi all,

    I am trying to process the following XML to add and set some properties to items:

    HTML Code:
    <lot xmlns:xsi=...>
       <id>...</id>
       <date>...</date>
       <desc>...</desc>
       <items>
          <item>...</item>
          <item>...</item>
                 ....
          <item>...</item>
       </items>
    
    </lot>
    . I use StexEventItemReader abd Jaxb2 unmarshaller for unmarshalling : all works fine.
    . I modify my Jaxb2 objects as expected
    . At marshalling step is my problem:
    I use StaxEventItemWriter and Jaxb2 marshaller, but i am not able to well reconstitute
    the XML file. What i obtain is something like:


    HTML Code:
    <lot>
    <lot>
       <id>...</id>
       <date>...</date>
       <desc>...</desc>
       <items>
          <item>...</item>
          <item>...</item>
                 ....
          <item>...</item>
       </items>
    
    </lot>
    </lot>
    as we can see: the root tag element is put twice for opening and closing the xml document.


    My configuration is like this:

    Code:
    <beans:bean id="myWriter" class="com.MyWriter">
        <beans:property name="delegate" ref="xmlWriter" />
     </beans:bean>
    
     <beans:bean id="xmlWriter" class="org.springframework.batch.item.xml.StaxEventItemWriter">
      <beans:property name="rootTagName" value="lot" />
      <beans:property name="marshaller" ref="marshaller" />
      <beans:property name="overwriteOutput" value="true" />
      <beans:property name="resource" ref="fichierOUT" />
      </beans:bean>
    
    <beans:bean id="marshaller"
          class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
          <beans:property name="classesToBeBound">
                <beans:list>           
                     <beans:value>Lot</beans:value> 
                     <beans:value>Items</beans:value>
                     <beans:value>Item</beans:value>
                </beans:list>
            </beans:property>
            <beans:property name="schema" value="file:./myXSD.xsd"/>
    </beans:bean>
    In the class MyWriter, in the 'write' method, the delegate writer (StaxEventItemWriter) writes the object transmitted in parameter (here a 'Lot' object):
    Code:
    delegate.write(lot)
    I tried to make the delegate write only the 'items' block, but in this case i lose the other information of the lot (see the following xml):

    HTML Code:
    <lot>
       <items>
          <item>...</item>
          <item>...</item>
                 ....
          <item>...</item>
       </items>
    </lot>

    What is wrong in my configuration? how is it possible to obtain the XML expected? If you have a sample of code doing that, it would be great!
    Thanks in advance ofr your help on this!
    Last edited by benmasi; Aug 4th, 2011, 08:42 AM.

  • #2
    The most likely cause is that you annotated your Lot class with @XmlRootElement(name="lot") and at the same time, as I can see, your rootTagName is set to "lot".
    That's why you see lot twice in the xml output file.

    Comment

    Working...
    X