This is my XML:
<?xml version="1.0"?>
<root xmlns="http://example.com/first-schema.xsd"
xmlns:f="http://example.com/second-schema.xsd">
<f:foo>test</f:foo>
</root>
Now I want to validate whether this XML is XMLSchema-valid. I don’t have these first-schema.xsd and second-schema.xsd files locally. Moreover, I don’t know anything about them. I just want to make sure that my XML document is valid against its schemas. Is it possible to do in Java?
You can use the javax.xml.validation APIs for this.
The example below demonstrates how to validate a JAXB object model against a schema, but you’ll see it’s easy to replace the JAXBSource with a DOMSource for DOM: