Announcement Announcement Module
No announcement yet.
How do I get StaxEventItemWriter to close a tag rather than using a end tag... Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • How do I get StaxEventItemWriter to close a tag rather than using a end tag...

    I know it is not exactly a Batch question but since it happens while using the StaxEventItemWriter...

    I wish to write a nillable tag which is empty by just closing it like this :

    <instituteID xmlns:xsi="" xsi:nil="true"/>
    but I get this instead:
    <instituteID xmlns:xsi="" xsi:nil="true">
    from this xsd :
    <xs:element name="instituteID" type="xs:string" nillable="true" />
    	<bean id="myDocumentItemWriter" class="org.springframework.batch.item.xml.StaxEventItemWriter" scope="step">
    		<property name="resource" value="file:#{jobParameters[]}" /> 
    		<property name="marshaller" ref="myMarshaller" />
    		<property name="rootTagName" value="{}documents" />
    		<property name="overwriteOutput" value="true" />
    		<property name="saveState" value="false" />
    	<bean id="myMarshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
    		<property name="contextPaths" value="some.model.context" />
    		<property name="schema" value="classpath:myXsd.xsd" />
    	    <property name="marshallerProperties">
    	                      <util:constant static-field="javax.xml.bind.Marshaller.JAXB_FORMATTED_OUTPUT"/>
    	                    <value type="boolean">true</value>
    is my Writer Configuration.

    Is my problem config related ? My knowledge of STAX / Parser internal stuff is limited, so I wonder if I am just missing something minor.... just searching the web did not help.

    Additionally the Marshaller properties don't seem to be used since my output is still unformatted, though setting is true.
    Last edited by Yvory; Nov 12th, 2010, 07:24 AM. Reason: mistake in text

  • #2
    I have a feeling that it is the StaX implementation itself that decides what to do with endElement events, so I don't know if you can change this behaviour. Maybe there is a System property or something - you need to read the docs for the implementation. We worked quite hard to make Spring Batch work with Woodstox, and I'm not sure if any other implementations even work any more, so Woodstox should be your starting point.

    Regarding the formatting: it is not the JAXB2 implementation doing the streaming, so I wouldn't expect that to have any effect. Again: have a look at the StaX docs.