2 Replies Latest reply on Jan 25, 2017 6:15 PM by Cheng Fang

    Write XML using XSD

    Richard Moore Master

      I have a project that involves reading a flat file and converting it to XML using the XSD the customer provided. Do you have a suggestion or example of writing XML based on an XSD?

        • 1. Re: Write XML using XSD
          Cheng Fang Master

          jberet-support contains reader and writers for flat files and xml files (see jberet-support javadocs):







          So you can use BeanIOItemReader for reading from flat files and XmlItemWriter for writing to xml output.  jberet-support tests directory should have tests for how to use BeanIOItemReader and XmlItemWriter.  For BeanIO reader, you will need to create a mapping file (required by BeanIO) to detail how to map input data fields to model object fields.


          Example BeanIO mapping files:




          Since the mapping is offloaded to the mapping file, the job.xml file for BeanIO reader is relatively simple:



          XmlItemWriter uses jackson libraries behind the scene, and usually it can automatically generate xml document from your mode objects (e.g., Person.class, Employee.class, etc).  In some cases, you will need to add a few jackson annotations to your model class to help the conversion.


          Example xmlItemWriter job.xml:


          • 2. Re: Write XML using XSD
            Cheng Fang Master

            there is no automatical way to write an object to xml based on its xsd.  If you use jberet-support xmlItemWriter, the mapping happens in your model class in the form of jackson and/or jaxb mapping annotations.