Spring Batch Example – MySQL Database To XML

In this tutorial, we will show you how to read data from a MySQL database, with JdbcCursorItemReader and JdbcPagingItemReader, and write it into an XML file. Tools and libraries used Maven 3 Eclipse 4.2 JDK 1.6 Spring Core 3.2.2.RELEASE Spring OXM 3.2.2.RELEASE Spring Batch 2.2.0.RELEASE MySQL Java Driver 5.1.25 P.S This example – MySQL jdbc …

Read more

JAXB hello world example

Jakarta XML Binding (JAXB; formerly Java Architecture for XML Binding) is an XML binding framework to convert Java objects to and from XML. XML Marshalling – Convert Java objects into XML. XML Unmarshalling – Convert XML back into Java Objects. Note This article will focus on Java 11, JAXB 3 and EclipseLink MOXy JAXB RI. …

Read more

Spring 3 MVC and XML example

In Spring 3, one of the feature of “mvc:annotation-driven“, is support for convert object to/from XML file, if JAXB is in project classpath. In this tutorial, we show you how to convert a return object into XML format and return it back to user via Spring @MVC framework. Technologies used : Spring 3.0.5.RELEASE JDK 1.6 …

Read more

XML example with Jersey + JAXB

This tutorial show you how to use JAXB to convert object to XML in Jersey, and return it back to user. 1. Dependency To integrate JAXB with Jersey, no extra dependency is required. Just include “jersey-server.jar” will do. 2. JAXB Annotation Annotate object with JAXB annotation, for conversion later. import javax.xml.bind.annotation.XmlAttribute; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; …

Read more

XML example with RESTEasy + JAXB

RESTEasy, is required JAXB to support XML file. In this tutorial, we show you how to create an “user” object, convert it into XML file, and return it back to the client. 1. RESTEasy + JAXB To use JAXB in RESTEasy, you need to include the “resteasy-jaxb-provider.jar” dependency. File : pom.xml <repositories> <repository> <id>JBoss repository</id> …

Read more

Spring MVC XmlViewResolver example

In Spring MVC, XmlViewResolver is used to resolve “view name” based on view beans in the XML file. By default, XmlViewResolver will loads the view beans from /WEB-INF/views.xml, however, this location can be overridden through the “location” property : <beans …> <bean class="org.springframework.web.servlet.view.XmlViewResolver"> <property name="location"> <value>/WEB-INF/spring-views.xml</value> </property> </bean> </beans> In above case, it loads the …

Read more

How to read XML file in Java – (JDOM Parser)

JDOM is open-source Java-based XML parser framework built on top of DOM and SAX, also a document object model(DOM) in-memory representation of an XML document. JDOM makes navigating XML documents easier by providing more straightforward APIs and a standard Java-based collection interface. If you don’t mind downloading a small library to parse an XML file, …

Read more

SAX Error – Content is not allowed in prolog

We use SAX parser to parse an XML file, and hist the following error message: Terminal org.xml.sax.SAXParseException; systemId: ../src/main/resources/staff.xml; lineNumber: 1; columnNumber: 1; Content is not allowed in prolog. In short, invalid text or BOM before the XML declaration or different encoding will cause the SAX Error – Content is not allowed in prolog. 1. …

Read more