DLESE Tools
v1.2

org.dlese.dpc.xml
Class XMLValidator

java.lang.Object
  extended byorg.dlese.dpc.xml.XMLValidator

public class XMLValidator
extends Object

XMLValidator uses Xerces to parse and validate xml files in a directory or an individual xml file you specify. Each xml file should contain a DOCTYPE declaration or a schema reference, which is used to perform the validation. XMLValidator then writes a report to the file path indicated listing the number of files validated and any validation problems encountered. How: Use JAXP SAXPaser to parse 1 .xml file or all the .xml files in a directory.

Author:
jweather

Field Summary
protected static boolean DEFAULT_DYNAMIC_VALIDATION
          Default dynamic validation support (false).
protected static boolean DEFAULT_MEMORY_USAGE
          Default memory usage report (false).
protected static boolean DEFAULT_NAMESPACE_PREFIXES
          Default namespace prefixes (false).
protected static boolean DEFAULT_NAMESPACES
          Default namespaces support (true).
protected static String DEFAULT_PARSER_NAME
          Default parser name.
protected static boolean DEFAULT_SCHEMA_FULL_CHECKING
          Default Schema full checking support (false).
protected static boolean DEFAULT_SCHEMA_VALIDATION
          Default Schema validation support (false).
protected static boolean DEFAULT_TAGGINESS
          Default "tagginess" report (false).
protected static boolean DEFAULT_VALIDATION
          Default validation support (false).
protected static String DYNAMIC_VALIDATION_FEATURE_ID
          Dynamic validation feature id (http://apache.org/xml/features/validation/dynamic).
protected static String NAMESPACE_PREFIXES_FEATURE_ID
          Namespace prefixes feature id (http://xml.org/sax/features/namespace-prefixes).
protected static String NAMESPACES_FEATURE_ID
          Namespaces feature id (http://xml.org/sax/features/namespaces).
protected static String SCHEMA_FULL_CHECKING_FEATURE_ID
          Schema full checking feature id (http://apache.org/xml/features/validation/schema-full-checking).
protected static String SCHEMA_VALIDATION_FEATURE_ID
          Schema validation feature id (http://apache.org/xml/features/validation/schema).
protected static String VALIDATION_FEATURE_ID
          Validation feature id (http://xml.org/sax/features/validation).
 
Constructor Summary
XMLValidator()
           
 
Method Summary
static void main(String[] args)
          The main program for the XMLValidator class
 StringBuffer validate(String filePath)
          Validate a single XML file or directory of XML files.
 StringBuffer validate(String filePath, String[] inputFileNames)
          Validate a single XML file or directory of XML files, processing only the xml files that match the ID list provided.
 StringBuffer validate(String filePath, String[] inputFileNames, String reportFilePath)
          Validate a single XML file or directory of XML files.
static String validateFile(File f)
          Validates an XML File to the external DTD or schema that is present in the File.
static String validateFile(File f, boolean showWarnings)
          Validates an XML File to the external DTD or schema that is present in the File.
static String validateString(String s)
          Validates an XML String to the external DTD or schema that is present in the String.
static String validateString(String s, boolean showWarnings)
          Validates an XML String to the external DTD or schema that is present in the String.
static String validateUri(String URI)
          Validates an XML document at the given URI.
static String validateUri(String URI, boolean showWarnings)
          Validates an XML document at the given URI.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NAMESPACES_FEATURE_ID

protected static final String NAMESPACES_FEATURE_ID
Namespaces feature id (http://xml.org/sax/features/namespaces).

See Also:
Constant Field Values

NAMESPACE_PREFIXES_FEATURE_ID

protected static final String NAMESPACE_PREFIXES_FEATURE_ID
Namespace prefixes feature id (http://xml.org/sax/features/namespace-prefixes).

See Also:
Constant Field Values

VALIDATION_FEATURE_ID

protected static final String VALIDATION_FEATURE_ID
Validation feature id (http://xml.org/sax/features/validation).

See Also:
Constant Field Values

SCHEMA_VALIDATION_FEATURE_ID

protected static final String SCHEMA_VALIDATION_FEATURE_ID
Schema validation feature id (http://apache.org/xml/features/validation/schema).

See Also:
Constant Field Values

SCHEMA_FULL_CHECKING_FEATURE_ID

protected static final String SCHEMA_FULL_CHECKING_FEATURE_ID
Schema full checking feature id (http://apache.org/xml/features/validation/schema-full-checking).

See Also:
Constant Field Values

DYNAMIC_VALIDATION_FEATURE_ID

protected static final String DYNAMIC_VALIDATION_FEATURE_ID
Dynamic validation feature id (http://apache.org/xml/features/validation/dynamic).

See Also:
Constant Field Values

DEFAULT_PARSER_NAME

protected static final String DEFAULT_PARSER_NAME
Default parser name.

See Also:
Constant Field Values

DEFAULT_NAMESPACES

protected static final boolean DEFAULT_NAMESPACES
Default namespaces support (true).

See Also:
Constant Field Values

DEFAULT_NAMESPACE_PREFIXES

protected static final boolean DEFAULT_NAMESPACE_PREFIXES
Default namespace prefixes (false).

See Also:
Constant Field Values

DEFAULT_VALIDATION

protected static final boolean DEFAULT_VALIDATION
Default validation support (false).

See Also:
Constant Field Values

DEFAULT_SCHEMA_VALIDATION

protected static final boolean DEFAULT_SCHEMA_VALIDATION
Default Schema validation support (false).

See Also:
Constant Field Values

DEFAULT_SCHEMA_FULL_CHECKING

protected static final boolean DEFAULT_SCHEMA_FULL_CHECKING
Default Schema full checking support (false).

See Also:
Constant Field Values

DEFAULT_DYNAMIC_VALIDATION

protected static final boolean DEFAULT_DYNAMIC_VALIDATION
Default dynamic validation support (false).

See Also:
Constant Field Values

DEFAULT_MEMORY_USAGE

protected static final boolean DEFAULT_MEMORY_USAGE
Default memory usage report (false).

See Also:
Constant Field Values

DEFAULT_TAGGINESS

protected static final boolean DEFAULT_TAGGINESS
Default "tagginess" report (false).

See Also:
Constant Field Values
Constructor Detail

XMLValidator

public XMLValidator()
Method Detail

main

public static void main(String[] args)
The main program for the XMLValidator class

Parameters:
args - The command line arguments

validate

public StringBuffer validate(String filePath)
                      throws FileNotFoundException,
                             IOException,
                             ParserConfigurationException,
                             SAXException,
                             Exception
Validate a single XML file or directory of XML files. Same as calling validate(String, null).

Parameters:
filePath - A single XML file or directory contianing XML files to be validated.
Returns:
StringBuffer A StringBuffer containing the validation report.
Throws:
FileNotFoundException - DESCRIPTION
IOException - DESCRIPTION
ParserConfigurationException - DESCRIPTION
SAXException - DESCRIPTION
Exception - DESCRIPTION

validate

public StringBuffer validate(String filePath,
                             String[] inputFileNames)
                      throws FileNotFoundException,
                             IOException,
                             ParserConfigurationException,
                             SAXException,
                             Exception
Validate a single XML file or directory of XML files, processing only the xml files that match the ID list provided. Same as calling validate(String, String [], null).

Parameters:
filePath - A single XML file or directory contianing XML files to be validated.
inputFileNames - An array of all the ID names found in the directory indicated in filePath to be validated. If null, then the list of files is obtained from the filePath directory.
Returns:
StringBuffer A StringBuffer containing the validation report.
Throws:
FileNotFoundException - DESCRIPTION
IOException - DESCRIPTION
ParserConfigurationException - DESCRIPTION
SAXException - DESCRIPTION
Exception - DESCRIPTION

validate

public StringBuffer validate(String filePath,
                             String[] inputFileNames,
                             String reportFilePath)
                      throws Exception
Validate a single XML file or directory of XML files. A report of what was found will be output to the given file specified.

Parameters:
filePath - A single XML file or directory contianing XML files to be validated.
inputFileNames - An array of all the ID names found in the directory indicated in filePath to be validated. If null, then the list of files is obtained from the filePath directory. the file list is obtained
reportFilePath - The file where a validation report will be appended. If null then nothing is written.
Returns:
StringBuffer A StringBuffer containing the validation report.
Throws:
Exception - DESCRIPTION

validateString

public static final String validateString(String s)
Validates an XML String to the external DTD or schema that is present in the String. The String must contain a DTD or schema declaration within. Returns null if the String is valid or an appropriate error message if not.

Parameters:
s - An XML String, which must include a DTD or schema declaration.
Returns:
Null if valid, else a String containing an appropriate error message.

validateString

public static final String validateString(String s,
                                          boolean showWarnings)
Validates an XML String to the external DTD or schema that is present in the String. The String must contain a DTD or schema declaration within. Returns null if the String is valid or an appropriate error message if not. The output message may contain only warnings if showWarnings is set to true.

Parameters:
s - An XML String, which must include a DTD or schema declaration.
showWarnings - Set to true to check for warnings as well as errors.
Returns:
Null if valid, else a String containing an appropriate error and/or warning message.

validateUri

public static final String validateUri(String URI)
Validates an XML document at the given URI. URI's must be of the form:

Parameters:
URI - A URI path to an XML document.
Returns:
Null if valid, else a String containing an appropriate error message.

validateUri

public static final String validateUri(String URI,
                                       boolean showWarnings)
Validates an XML document at the given URI. URI's must be of the form:

Parameters:
URI - A URI path to an XML document.
showWarnings - Set to true to check for warnings as well as errors.
Returns:
Null if valid, else a String containing an appropriate error message.

validateFile

public static final String validateFile(File f)
Validates an XML File to the external DTD or schema that is present in the File. The File must contain a DTD or schema declaration within. Returns null if the File is valid or an appropriate error message if not.

Parameters:
f - An XML File, which must include a DTD or schema declaration.
Returns:
Null if valid, else a String containing an appropriate error message.

validateFile

public static final String validateFile(File f,
                                        boolean showWarnings)
Validates an XML File to the external DTD or schema that is present in the File. The File must contain a DTD or schema declaration within. Returns null if the File is valid or an appropriate error message if not. The output message may contain only warnings if showWarnings is set to true.

Parameters:
f - An XML File, which must include a DTD or schema declaration.
showWarnings - Set to true to check for warnings as well as errors.
Returns:
Null if valid, else a String containing an appropriate error and/or warning message.

DLESE Tools
v1.2