1
如何测试xml字符串以查看它是否对dtd文件进行验证?使用Java中的外部DTD进行XML验证
我读过this question,但他们只看到要在xml文件中替换dtd声明。
Person.DTD
<?xml version="1.0" encoding="UTF-8"?>
<!ELEMENT person (id)>
<!ELEMENT id (#PCDATA)>
测试
@Test
public void should_serialize_a_shootout_to_xml_and_validate_against_a_dtd(){
String xml = "<person><id>12</id></person>";
Assert.assertTrue(validate_xml("person.dtd",xml));
}
boolean validate_xml(String dtd_filename,String xml){
//check xml and throw validation errors
throw new NotImplementedException();
}
谢谢!
的[验证对本地DTD F侧XML文件可能重复ile与Java](http://stackoverflow.com/questions/1096365/validate-an-xml-file-against-local-dtd-file-with-java) – bmargulies 2011-09-08 19:14:08