开发者

XML validation using dtd

I am using the following snippet to write an XML file. I need to throw an exception if the document is not valid one. How can I do validation in this piece of code?

private static void writeToFile(Node node, File file) throws Exception {
    TransformerFactory tf = TransformerFactory.newInstance();
    tf.setAttribute("indent-n开发者_运维知识库umber", new Integer(4));
    Transformer transformer = tf.newTransformer();
    transformer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, "schema.dtd");
    transformer.setOutputProperty(OutputKeys.INDENT, "yes");
    transformer.transform(new DOMSource(node), new StreamResult(new FileWriter(file)));
}


You have to implement the EntityResolver, checkout this example.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜