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