Class XMLValidator

java.lang.Object
org.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:
John Weatherley
  • Field Details

    • NAMESPACES_FEATURE_ID

      protected static final String NAMESPACES_FEATURE_ID
      Namespaces feature id (http://xml.org/sax/features/namespaces).
      See Also:
    • 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:
    • VALIDATION_FEATURE_ID

      protected static final String VALIDATION_FEATURE_ID
      Validation feature id (http://xml.org/sax/features/validation).
      See Also:
    • 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:
    • 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:
    • 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:
    • DEFAULT_PARSER_NAME

      protected static final String DEFAULT_PARSER_NAME
      Default parser name.
      See Also:
    • DEFAULT_NAMESPACES

      protected static final boolean DEFAULT_NAMESPACES
      Default namespaces support (true).
      See Also:
    • DEFAULT_NAMESPACE_PREFIXES

      protected static final boolean DEFAULT_NAMESPACE_PREFIXES
      Default namespace prefixes (false).
      See Also:
    • DEFAULT_VALIDATION

      protected static final boolean DEFAULT_VALIDATION
      Default validation support (false).
      See Also:
    • DEFAULT_SCHEMA_VALIDATION

      protected static final boolean DEFAULT_SCHEMA_VALIDATION
      Default Schema validation support (false).
      See Also:
    • DEFAULT_SCHEMA_FULL_CHECKING

      protected static final boolean DEFAULT_SCHEMA_FULL_CHECKING
      Default Schema full checking support (false).
      See Also:
    • DEFAULT_DYNAMIC_VALIDATION

      protected static final boolean DEFAULT_DYNAMIC_VALIDATION
      Default dynamic validation support (false).
      See Also:
    • DEFAULT_MEMORY_USAGE

      protected static final boolean DEFAULT_MEMORY_USAGE
      Default memory usage report (false).
      See Also:
    • DEFAULT_TAGGINESS

      protected static final boolean DEFAULT_TAGGINESS
      Default "tagginess" report (false).
      See Also:
  • Constructor Details

    • XMLValidator

      public XMLValidator()
  • Method Details

    • main

      public static void main(String[] args)
      The main program for the XMLValidator class
      Parameters:
      args - The command line arguments
    • validate

      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

      Throws:
      FileNotFoundException
      IOException
      ParserConfigurationException
      SAXException
      Exception
    • validate

      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, Date modifiedSinceDate) 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:
      • file:///usr/local/nonesuch.xml - an XML document on the local system.
      • http://www.nonesuch.com/nonsuch.xml - an XML document on the Internet.
      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:
      • file:///usr/local/nonesuch.xml - an XML document on the local system.
      • http:///www.nonesuch.com/nonsuch.xml - an XML document on the Internet.
      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.