Last update: 2011-06-23

org.proteios.io
Class XMLValidator

java.lang.Object
  extended by org.proteios.io.XMLValidator

public class XMLValidator
extends Object

This class validates XML input (file, input stream, or SourceStream) against an XSD (XML Schema Definition) file. Based on Validate.java by Neeraj Bajaj, Sun Microsystems, in example code described here.

Version:
2.0
Author:
Olle
Last modified
$Date: 2009-05-07 11:43:55 +0200 (Thu, 07 May 2009) $

Constructor Summary
XMLValidator()
           
 
Method Summary
static Schema compileSchema(String xsdFilePath)
          Parses the XSD schema file and returns in-memory representation of the schema.
static boolean validate_w_error_output(String xsdFilePath, InputStream xmlInputStream)
          Validates an XML input stream against the schema in an XSD schema file.
static boolean validate_w_error_output(String xsdFilePath, StreamSource xmlStreamSource)
          Validates an XML StreamSource against the schema in an XSD schema file.
static boolean validate_w_error_output(String xsdFilePath, String xmlFilePath)
          Validates an XML file against the schema in an XSD schema file.
static boolean validate(String xsdFilePath, InputStream xmlInputStream)
          Validates an XML input stream against the schema in an XSD schema file.
static boolean validate(String xsdFilePath, StreamSource xmlStreamSource)
          Validates an XML file StreamSource against the schema in an XSD schema file.
static boolean validate(String xsdFilePath, String xmlFilePath)
          Validates an XML file against the schema in an XSD schema file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XMLValidator

public XMLValidator()
Method Detail

compileSchema

public static Schema compileSchema(String xsdFilePath)
                            throws SAXException
Parses the XSD schema file and returns in-memory representation of the schema.

Parameters:
xsdFilePath - String with path to XSD file with validation schema.
Returns:
Schema In-memory representation of the XSD file schema.
Throws:
SAXException

validate

public static boolean validate(String xsdFilePath,
                               String xmlFilePath)
                        throws SAXException
Validates an XML file against the schema in an XSD schema file.

Parameters:
xsdFilePath - String with path to XSD file with validation schema.
xmlFilePath - String with path to XML file to validate.
Returns:
True if XML file is valid, else false.
Throws:
SAXException

validate

public static boolean validate(String xsdFilePath,
                               InputStream xmlInputStream)
                        throws SAXException
Validates an XML input stream against the schema in an XSD schema file.

Parameters:
xsdFilePath - String with path to XSD file with validation schema.
xmlInputStream - XML input stream to validate.
Returns:
True if XML input stream is valid, else false.
Throws:
SAXException

validate

public static boolean validate(String xsdFilePath,
                               StreamSource xmlStreamSource)
                        throws SAXException
Validates an XML file StreamSource against the schema in an XSD schema file.

Parameters:
xsdFilePath - String with path to XSD file with validation schema.
xmlStreamSource - XML StreamSource to validate.
Returns:
True if XML StreamSource is valid, else false.
Throws:
SAXException

validate_w_error_output

public static boolean validate_w_error_output(String xsdFilePath,
                                              String xmlFilePath)
                                       throws SAXException
Validates an XML file against the schema in an XSD schema file. Prints error information if file not valid.

Parameters:
xsdFilePath - String with path to XSD file with validation schema.
xmlFilePath - String with path to XML file to validate.
Returns:
True if XML file is valid, else false.
Throws:
SAXException

validate_w_error_output

public static boolean validate_w_error_output(String xsdFilePath,
                                              InputStream xmlInputStream)
                                       throws SAXException
Validates an XML input stream against the schema in an XSD schema file. Prints error information if XML input stream not valid.

Parameters:
xsdFilePath - String with path to XSD file with validation schema.
xmlInputStream - XML input stream to validate.
Returns:
True if XML input stream is valid, else false.
Throws:
SAXException

validate_w_error_output

public static boolean validate_w_error_output(String xsdFilePath,
                                              StreamSource xmlStreamSource)
                                       throws SAXException
Validates an XML StreamSource against the schema in an XSD schema file. Prints error information if StreamSource not valid.

Parameters:
xsdFilePath - String with path to XSD file with validation schema.
xmlStreamSource - XML StreamSource to validate.
Returns:
True if XML StreamSource is valid, else false.
Throws:
SAXException

Last update: 2011-06-23