Announcement Announcement Module
Collapse
No announcement yet.
XML Output doubled tag Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

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

    Comment


    • #3
      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!

      Comment

      Working...
      X