java.lang.Object
esa.opensf.osfi.xmlutils.XmlFiles
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic LoadResult<Document>Read and parse a XML document, without validation.static LoadResult<Document>Read and parse a XML document, without validation.static LoadResult<Document>loadAndValidate(File file, File schema, String schemaLang, boolean stopOnFirstError) Read and parse a XML document, validating against an internal or external schema.static LoadResult<Void>Validates an XML file against a schema.
-
Field Details
-
W3C_NS_URI_XSD10
Default version of the XSD standard; Java 8 states that at least XSD 1.0 is supported.- See Also:
-
W3C_NS_URI_XSD11
XSD standard version 1.1 (specifically). It may not be supported if not using a specific library e.g. Xerces-J 2.11 or later.- See Also:
-
-
Method Details
-
load
Read and parse a XML document, without validation. Equivalent to calling the other overload withtrueas the second argument- Parameters:
file- Path to the XML document- Returns:
- Object containing the result (if successful) and the list of parsing errors (if not).
- Throws:
FileNotFoundException- if the file cannot be read.- See Also:
-
load
public static LoadResult<Document> load(File file, boolean stopOnFirstError) throws FileNotFoundException Read and parse a XML document, without validation.- Parameters:
file- Path to the XML documentstopOnFirstError- If true, parsing will stop once any error is found. Otherwise, only a fatal error will stop the process and all errors will be logged.- Returns:
- Object containing the result (if successful) and the list of parsing errors (if not).
- Throws:
FileNotFoundException- if the file cannot be read.- See Also:
-
loadAndValidate
public static LoadResult<Document> loadAndValidate(File file, File schema, String schemaLang, boolean stopOnFirstError) throws FileNotFoundException Read and parse a XML document, validating against an internal or external schema.- Parameters:
file- Path to the XML documentschema- Path to the schemaschemaLang- One of the constants in this class denoting a schema language.stopOnFirstError- If true, validation will stop once any error is found. Otherwise, only a fatal error will stop the process and all errors will be logged.- Returns:
- An object containing the result (if successful) and the list of parsing/validation warnings and errors.
- Throws:
FileNotFoundException- if the file cannot be loaded.- See Also:
-
validate
public static LoadResult<Void> validate(File xmlFile, File schemaFile, String schemaLanguage, boolean stopOnFirstError) Validates an XML file against a schema. This function never throws.- Parameters:
xmlFile- XML file location, must not be null.schemaFile- Schema file location. If null, the result depends on the schema language. For XSD, a schema linked by the XML file ("internal schema") will be used.schemaLanguage- Constant for the schema language to use.stopOnFirstError- If true, processing will be interrupted on the first error issued.- Returns:
- An instance of
LoadResultwith the parse+validation events. The result field itself is alwaysnull. - See Also:
-