java.lang.Object
com.github.ushiosan23.jvm.xml.XMLUtils
-
Method Summary
Modifier and TypeMethodDescriptiongenerateValidator(@Nullable InputStream schemaValidator, @Nullable String schemaLanguage) Generates an XML file validator.static Documentload(@NotNull File location, IApply.EmptyResult<DocumentBuilderFactory> apply) Load xml fileload(@NotNull InputStream stream, IApply.EmptyResult<DocumentBuilderFactory> apply) Load xml streamstatic Documentload(@NotNull URL location, IApply.EmptyResult<DocumentBuilderFactory> apply) Load xml urlstatic Documentload(@NotNull Path location, IApply.EmptyResult<DocumentBuilderFactory> apply) Load xml file pathstatic booleanvalidate(@NotNull InputStream xml, @Nullable String schemaLanguage, @Nullable InputStream schemaValidator) Validates an XML file using a schema file.
-
Method Details
-
load
public static Document load(@NotNull @NotNull File location, @Nullable IApply.EmptyResult<DocumentBuilderFactory> apply) throws IOException, ParserConfigurationException, SAXException Load xml file- Parameters:
location- The xml locationapply- Action to execute to configure factory instance- Returns:
- Returns a document instance
- Throws:
IOException- Error to open fileParserConfigurationException- Error factory configurationSAXException- Error to parse xml file
-
load
public static Document load(@NotNull @NotNull Path location, @Nullable IApply.EmptyResult<DocumentBuilderFactory> apply) throws IOException, ParserConfigurationException, SAXException Load xml file path- Parameters:
location- File locationapply- Action to execute to configure factory instance- Returns:
- Returns a document instance
- Throws:
IOException- Error to open fileParserConfigurationException- Error factory configurationSAXException- Error to parse xml file
-
load
public static Document load(@NotNull @NotNull URL location, @Nullable IApply.EmptyResult<DocumentBuilderFactory> apply) throws IOException, ParserConfigurationException, SAXException Load xml url- Parameters:
location- URL locationapply- Action to execute to configure factory instance- Returns:
- Returns a document instance
- Throws:
IOException- Error to open fileParserConfigurationException- Error factory configurationSAXException- Error to parse xml file
-
load
@NotNull public static @NotNull Document load(@NotNull @NotNull InputStream stream, @Nullable IApply.EmptyResult<DocumentBuilderFactory> apply) throws IOException, ParserConfigurationException, SAXException Load xml stream- Parameters:
stream- XML Streamapply- Action to execute to configure factory instance- Returns:
- Returns a document instance
- Throws:
IOException- Error to process the streamParserConfigurationException- Error factory configurationSAXException- Error to parse xml file
-
validate
public static boolean validate(@NotNull @NotNull InputStream xml, @Nullable @Nullable String schemaLanguage, @Nullable @Nullable InputStream schemaValidator) Validates an XML file using a schema file.- Parameters:
xml- The XML file you want to validateschemaLanguage- The validator you want to use. SeeXMLConstants.W3C_XML_SCHEMA_NS_URIandXMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URIschemaValidator- The file containing the validation schema- Returns:
- Returns
trueif the xml file is valid orfalseif it is invalid or an error has occurred.
-
generateValidator
@NotNull public static @NotNull Validator generateValidator(@Nullable @Nullable InputStream schemaValidator, @Nullable @Nullable String schemaLanguage) throws IOException, SAXException Generates an XML file validator.- Parameters:
schemaValidator- XML schema fileschemaLanguage- The validator you want to use. SeeXMLConstants.W3C_XML_SCHEMA_NS_URIandXMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI- Returns:
- Returns an instance of
Validatorconfigured for use. - Throws:
IOException- IO errorSAXException- If an error occurred during parsing
-