Jin Kwon
Jin Kwon

Reputation: 21976

How to read simple xml list with Spring Batch?

<parent>
  <child>aaa</child> <!-- simple string -->
  <child>bbb</child>
  ...
</parent>

How can I read those children's value and processing with following processor?

@Override
public void write(final List<? extends String> children) {
}

Note that I don't have any schedule to make a binding class mapping to <parent/>.

Upvotes: 1

Views: 958

Answers (1)

Luca Basso Ricci
Luca Basso Ricci

Reputation: 18383

Make child the fragment root element and map its value as java.lang.String.

<bean name="reader" class="org.springframework.batch.item.xml.StaxEventItemReader">
  <property name="fragmentRootElementName" value="child" />
  <property name="resource" value="classpath:/xmlStringReader/source.xml" />
  <property name="unmarshaller" ref="unmarshaller" />
</bean>
<bean name="unmarshaller" class="org.springframework.oxm.xstream.XStreamMarshaller">
  <property name="aliases">
    <map>
      <entry key="child" value="java.lang.String" />
    </map>
  </property>
</bean>

Upvotes: 2

Related Questions