I have a .wsdl
file with an embedded schema. I want to validate an XML file/string using that .wsdl
file (the same way you would validate against an .xsd
). The schema is between the <types>
tag. I have this so far:
public boolean validate(String xmlString) {
try {
// Convert to input stream
InputStream xml = new ByteArrayInputStream(xmlString.getBytes());
SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Schema schema = schemaFactory.newSchema(new File("wsdl_filepath"));
// Validate against wsdl
Validator validator = schema.newValidator();
validator.validate(new StreamSource (xml));
// XML Message is valid
return true;
} catch (SAXException e) {
e.printStackTrace();
return false;
} catch (IOException e) {
e.printStackTrace();
return false;
}
}
This doesn't work, however. This validator works if validating against an .xsd
. I'm not sure how to modify it to validate against the embedded schema.
Any help would be appreciated, thank you!
Copyright Notice:Content Author:「o.o」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/37546182/java-validate-xml-against-an-embedded-schema-in-wsdl