Package org.dlese.dpc.xml
Class XMLValidator
java.lang.Object
org.dlese.dpc.xml.XMLValidator
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 Summary
FieldsModifier and TypeFieldDescriptionprotected static final booleanDefault dynamic validation support (false).protected static final booleanDefault memory usage report (false).protected static final booleanDefault namespace prefixes (false).protected static final booleanDefault namespaces support (true).protected static final StringDefault parser name.protected static final booleanDefault Schema full checking support (false).protected static final booleanDefault Schema validation support (false).protected static final booleanDefault "tagginess" report (false).protected static final booleanDefault validation support (false).protected static final StringDynamic validation feature id (http://apache.org/xml/features/validation/dynamic).protected static final StringNamespace prefixes feature id (http://xml.org/sax/features/namespace-prefixes).protected static final StringNamespaces feature id (http://xml.org/sax/features/namespaces).protected static final StringSchema full checking feature id (http://apache.org/xml/features/validation/schema-full-checking).protected static final StringSchema validation feature id (http://apache.org/xml/features/validation/schema).protected static final StringValidation feature id (http://xml.org/sax/features/validation). -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidThe main program for the XMLValidator classValidate a single XML file or directory of XML files.Validate a single XML file or directory of XML files, processing only the xml files that match the ID list provided.Validate a single XML file or directory of XML files.static final StringvalidateFile(File f) Validates an XML File to the external DTD or schema that is present in the File.static final StringvalidateFile(File f, boolean showWarnings) Validates an XML File to the external DTD or schema that is present in the File.static final StringValidates an XML String to the external DTD or schema that is present in the String.static final StringvalidateString(String s, boolean showWarnings) Validates an XML String to the external DTD or schema that is present in the String.static final StringvalidateUri(String URI) Validates an XML document at the given URI.static final StringvalidateUri(String URI, boolean showWarnings) Validates an XML document at the given URI.
-
Field Details
-
NAMESPACES_FEATURE_ID
Namespaces feature id (http://xml.org/sax/features/namespaces).- See Also:
-
NAMESPACE_PREFIXES_FEATURE_ID
Namespace prefixes feature id (http://xml.org/sax/features/namespace-prefixes).- See Also:
-
VALIDATION_FEATURE_ID
Validation feature id (http://xml.org/sax/features/validation).- See Also:
-
SCHEMA_VALIDATION_FEATURE_ID
Schema validation feature id (http://apache.org/xml/features/validation/schema).- See Also:
-
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
Dynamic validation feature id (http://apache.org/xml/features/validation/dynamic).- See Also:
-
DEFAULT_PARSER_NAME
Default parser name.- See Also:
-
DEFAULT_NAMESPACES
protected static final boolean DEFAULT_NAMESPACESDefault namespaces support (true).- See Also:
-
DEFAULT_NAMESPACE_PREFIXES
protected static final boolean DEFAULT_NAMESPACE_PREFIXESDefault namespace prefixes (false).- See Also:
-
DEFAULT_VALIDATION
protected static final boolean DEFAULT_VALIDATIONDefault validation support (false).- See Also:
-
DEFAULT_SCHEMA_VALIDATION
protected static final boolean DEFAULT_SCHEMA_VALIDATIONDefault Schema validation support (false).- See Also:
-
DEFAULT_SCHEMA_FULL_CHECKING
protected static final boolean DEFAULT_SCHEMA_FULL_CHECKINGDefault Schema full checking support (false).- See Also:
-
DEFAULT_DYNAMIC_VALIDATION
protected static final boolean DEFAULT_DYNAMIC_VALIDATIONDefault dynamic validation support (false).- See Also:
-
DEFAULT_MEMORY_USAGE
protected static final boolean DEFAULT_MEMORY_USAGEDefault memory usage report (false).- See Also:
-
DEFAULT_TAGGINESS
protected static final boolean DEFAULT_TAGGINESSDefault "tagginess" report (false).- See Also:
-
-
Constructor Details
-
XMLValidator
public XMLValidator()
-
-
Method Details
-
main
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- DESCRIPTIONIOException- DESCRIPTIONParserConfigurationException- DESCRIPTIONSAXException- DESCRIPTIONException- DESCRIPTION
-
validate
public StringBuffer validate(String filePath, Date modifiedSinceDate) throws FileNotFoundException, IOException, ParserConfigurationException, SAXException, Exception -
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- DESCRIPTIONIOException- DESCRIPTIONParserConfigurationException- DESCRIPTIONSAXException- DESCRIPTIONException- 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 obtainedreportFilePath- 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
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
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
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
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
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
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.
-