3
我想用JaXB驗證xml文檔。最簡單的JaXB驗證
代碼:
SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Schema schema = factory.newSchema(new StreamSource(new File("D:/liferay-develop/workspace/cat_test/v2/STD_MP.xsd")));
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
jaxbUnmarshaller.setSchema(schema);
現在我想,如果沒有文件來的Valide架構得到錯誤。在示例中,可以看到人們爲此創建了EventHandler類(如http://blog.bdoughan.com/2010/12/jaxb-and-marshalunmarshal-schema.html)。但也許存在更簡單的方法來得到驗證錯誤在conlose和變量?
謝謝它的工作。 –