Announcement Announcement Module
Collapse
No announcement yet.
How do I get StaxEventItemWriter to close a tag rather than using a end tag... Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • 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 :

    Code:
    <instituteID xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
    but I get this instead:
    Code:
    <instituteID xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true">
    </instituteID>
    from this xsd :
    Code:
    <xs:element name="instituteID" type="xs:string" nillable="true" />
    Code:
    	<bean id="myDocumentItemWriter" class="org.springframework.batch.item.xml.StaxEventItemWriter" scope="step">
    		<property name="resource" value="file:#{jobParameters[output.file.name]}" /> 
    
    		<property name="marshaller" ref="myMarshaller" />
    		<property name="rootTagName" value="{http://www.myCompany.de/1_1}documents" />
    		<property name="overwriteOutput" value="true" />
    		<property name="saveState" value="false" />
    	</bean>
    
    	<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">
    	            <map>
    	                <entry>
    	                    <key>
    	                      <util:constant static-field="javax.xml.bind.Marshaller.JAXB_FORMATTED_OUTPUT"/>
    	                    </key>
    	                    <value type="boolean">true</value>
    	                </entry>
    	            </map>
    	    </property>
    	</bean>
    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.

    Comment

    Working...
    X