Results 1 to 3 of 3

Thread: XML Output doubled tag

Hybrid View

  1. #1
    Join Date
    Feb 2011
    Posts
    6

    Unhappy XML Output doubled tag

    Hello, I'm pretty new with using this framework. I'm having an issue while creating and xml output.
    My problem is that my required xml output does not have any root tag. It looks like this...


    <tag1>
    <tag2>value</tag2>
    <tag3>
    <tag4>value</tag4>
    .
    .
    .
    <tag4>value</tag4>
    </tag3>
    </tag1>


    I've created and object Tag1 which hast two attributes
    tag2 is a String and tag3 is an object Type3 (which contains tag4 etc etc)

    I've have this configuration in my xml


    <bean id="diffusionItemWriter" class="org.springframework.batch.item.xml.StaxEven tItemWriter" >
    <property name="rootTagName" value="tag1"/>
    <property name="overwriteOutput" value="true"/>
    <property name="resource" ref="outputResource" />
    <property name="marshaller" ref="webSiteObjectMarshaller" />
    </bean>


    <bean id="webSiteObjectMarshaller" class="org.springframework.oxm.xstream.XStreamMars haller">
    <property name="aliases">
    <bean class="org.springframework.beans.factory.config.Ma pFactoryBean">
    <property name="targetMapClass">
    <value>java.util.HashMap</value>
    </property>
    <property name="sourceMap">
    <map>
    <entry key="tag1" value="com.package.Tag1" />
    <entry key="tag3" value="com.package.Tag3" />
    ......
    </map>
    </property>
    </bean>
    </property>
    </bean>


    But my output looks actually like this...

    <tag1>
    <tag1>
    <tag2>value</tag2>
    <tag3>
    <tag4>value</tag4>
    .
    .
    .
    <tag4>value</tag4>
    </tag3>
    </tag1>
    </tag1>


    Any help to avoid that extra tag will be much appreciated!

  2. #2
    Join Date
    Jun 2005
    Posts
    4,231

    Default

    That looks right to me. You set the rootTagName=tag1, which looks like an error since it is the same as your item wrapper outer tag, so that is the root tag that is emitted. What do you think it should look like?

  3. #3
    Join Date
    Feb 2011
    Posts
    6

    Default

    Hi!... I've solved my problem by deleting my Tag1 object and creating a list of objects Tag2 and Tag3 in my ItemReader (both object extends from a custom Abstract Object TagAbastract) and my Reader iterates over a list of TagAbastract objects.

    Now I got the expected output

    Thanks!

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •