问题描述:

I'm using springbatch to read my xml which is like this

<document xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

<dateCreation>2014-08-08T09:00:00</dateCreation>

<code>737</code>

<reseau>U</reseau>

<documentsPDF>

<documentPDF>

<referenceU>4567737123</referenceU>

<numCompte>121331312</numCompte>

<numS>123131</numS>

<numH>7001012</numH>

</documentPDF>

<documentPDF>

<referenceU>xcsdqszzezed</referenceU>

<numCompte>sdzdzdzdze</numCompte>

<numS>1146456788</numS>

<numH>7001012</numH>

</documentPDF>

</documentsPDF>

I've seen that in spring doc that the xml should contain only item as root element

how could I set my as root element for my item reader? something like this?

@Test

public void testItemStream() throws UnexpectedInputException, ParseException, Exception {

StaxEventItemReader<DocumentPDFType> xmlStaxEventItemReader = new StaxEventItemReader<>();

final Resource resource = new ClassPathResource("input/cuXXX/exemple_U.xml");

Jaxb2Marshaller docPDFUnmarshaller = new Jaxb2Marshaller();

docPDFUnmarshaller.setClassesToBeBound(DocumentPDFType.class);

xmlStaxEventItemReader.setUnmarshaller(docPDFUnmarshaller);

xmlStaxEventItemReader.setResource(resource);

xmlStaxEventItemReader.setFragmentRootElementName("documentPDF");

xmlStaxEventItemReader.open(new ExecutionContext());

boolean hasNext = true;

DocumentPDFType docPdf = null;

while (hasNext) {

docPdf = xmlStaxEventItemReader.read();

if (docPdf == null) {

hasNext = false;

} else {

System.out.println(docPdf);

}

}

}

but this is not working it's saying

[com.sun.istack.SAXParseException2; lineNumber: 11; columnNumber: 3; élément inattendu (URI : "", local : "documentPDF"). Les éléments attendus sont (none)]

相关阅读:
Top