Skip to Content
avatar image
Former Member

XML Validation using JAVA


I have a JAVA program:

package dTDValidate;
import org.w3c.dom.*;
import org.xml.sax.*;
import javax.xml.parsers.*;
import javax.xml.validation.*;
import javax.xml.transform.*;
import javax.xml.transform.dom.DOMSource;

public class DTDValidateXML {
	public static void main(String args[]) {	
			DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
			DocumentBuilder builder = factory.newDocumentBuilder();
			builder.setErrorHandler(new org.xml.sax.ErrorHandler() {
				//Ignore the fatal errors
				public void fatalError(SAXParseException exception)throws SAXException { }
				//Validation errors 
				public void error(SAXParseException e)throws SAXParseException {
					System.out.println("Error at " +e.getLineNumber() + " line.");
				//Show warnings
				public void warning(SAXParseException err)throws SAXParseException{
			Document xmlDocument = builder.parse(new FileInputStream("Employee.xml"));
			DOMSource source = new DOMSource(xmlDocument);
			StreamResult result = new StreamResult(System.out);
			TransformerFactory tf = TransformerFactory.newInstance();
			Transformer transformer = tf.newTransformer();
			transformer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, "Employee.dtd");
			transformer.transform(source, result);
		catch (Exception e) {

I have some queries about the above code:

1) I have to select Receiving Service based on the output of the JAVA validation code and I am using Enhanced Receiver Determination. What modification should be made to the above code to ensure so that the correct Receiver Service is populated by the above JAVA code as per the output.

For example:

If no error, Receiver Service should be Service1

If error, Receiver Service should be Service2

Please help.

Thank you,


Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

1 Answer

  • avatar image
    Former Member
    Oct 01, 2010 at 06:34 AM


    Do u mean that u will make a Adapter Module and deploy it, and wil use for validating the XML?

    What exactly XML Validation u r tring to do, data or XML Syntax?

    Please confirm these because u can achieve the same withot code also...


    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      Hi Pankaj,

      Ok then go for Integration Engine XML Validation.

      In Java mapping evaluate the source and then if any error return the Acknowledgement accordingly.

      I prefer going for 1:2 multimapping in Java.

      Both targets/message types has occurence 0..1