From: James A. <jam...@gm...> - 2006-12-21 10:23:15
|
I'm writing a patch for consideration that will handle schema validation. My use case is as follows: An XML document is generated in some fashion, but it does not contain xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="somenamespace somelocation" So I would like to set some properties on a Validator like this: validator = new Validator(new FileReader(xmlFile)); validator.setSchemaNamespace("http://www.example.com/xmlns/books"); validator.setSchemaURL(xsdFile.toURL()); validator.useXMLSchema(true); validator.assertIsValid(); This is what my patch is aiming to provide. Comments on the API and intended usage are welcome. In developing the tests for this patch though, I seem to have hit a bug, and was hoping someone could help me see what I'm doing wrong. The below tests fail, although I don't think they should. I can't see what properties I should be setting that would cause it to pass. import org.custommonkey.xmlunit.DetailedDiff; import org.custommonkey.xmlunit.Diff; import org.custommonkey.xmlunit.XMLTestCase; public class XMLUnitNamespaceTestCase extends XMLTestCase { private String expected = "<root xmlns='http://www.example.com/xmlns/example'" + " xmlns:xsi='http://exampe.com/xmlns/not/schema-instance/namespace' />";; private String actual = "<root xmlns='http://www.example.com/xmlns/example' />"; public void testNamespaceDifferencesFailViaAssertXMLMethod() throws Exception { assertXMLNotEqual(expected, actual); } public void testNamespaceDifferencesFailViaDetailedDiff() throws Exception { Diff diff = compareXML(expected, actual); DetailedDiff detailedDiff = new DetailedDiff(diff); assertFalse(detailedDiff.similar()); } } Cheers, James |