XML validation with an external DTD in Java -
How can I test an XML string to see if it is valid against the file and what is it?
I have read, but they only talk about changing the dtd declaration on an XML file.
Person.DTD
& lt ;? Xml version = "1.0" encoding = "UTF-8" & gt; & Lt ;! ELEMENT person (id) & gt; & Lt ;! ELEMENT ID (#PCDATA) & gt;
Test
@Test Public Zero should_serialize_a_shootout_to_xml_and_validate_against_a_dtd () {string xml = "& lt; person & gt; & lt; id & gt; 12 & Lt; / id & gt; & lt; / person & gt; "; Assert.assertTrue (validate_xml ("person.dtd", XML)); } Boolean validator _xml (string dtd_filename, string xml) {// check xml and throw validation errors new NotImplementedException (); }
Thanks!
I can come back sometime later, but here is the process that my mind has springs :
- Wrap the string with StringReader
- SAX Parser
- Make valid, track the number of SAX handler error examples that are parsed file < Li> Valid zero error
Comments
Post a Comment