I have a .zip file that contains .xml and .xsd file.
I'm reading it with a code similar to this one . Now, when I try to parse the .xml I get an error that schema is not found. How do I load the .xsd beforehand and then parse the .xml using that?
Get the ZipInputStream from the ZipFile - Reading text files in a zip archive
Use javax.xml.transform.stream.StreamSource - http://docs.oracle.com/javase/1.5.0/docs/api/javax/xml/transform/stream/StreamSource.html
SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); Schema schema = sf.newSchema(new StreamSource(xsdZipInputStream)); Validator validator = schema.newValidator(); validator.validate(xml);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.