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):

           

          org.jberet.support.io.BeanIOItemReader

          org.jberet.support.io.BeanIOItemWriter

          org.jberet.support.io.XmlItemReader

          org.jberet.support.io.XmlItemWriter

           

          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:

          person-beanio-mapping.xml

          star-entity-beanio-mapping.xml

           

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

          org.jberet.support.io.BeanIOReaderWriterTest.xml

           

          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:

          org.jberet.support.io.XmlItemReaderTest.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.