From: Majumder, A. <Ana...@Om...> - 2007-05-04 13:14:44
|
Stephan - I have another question. I am trying to compare two xml documents but would like to=20 Skip the comparison in a few of those nodes (e.g the documents should be treated as identical even if two elements 'foo' and 'bar' are different in the two). I see in the examples, that we could implement the DifferenceListener, but it seems like then the documents would be treated as similar/identical even if nodes other than 'foo' and 'bar' are different. Is there a way so that I can specify using xpaths, that I would like to skip comparison of just foo and bar. Thank you. Anamika. -----Original Message----- From: Majumder, Anamika=20 Sent: Thursday, May 03, 2007 11:18 AM To: 'Stefan Bodewig'; xml...@li... Subject: RE: [Xmlunit-general] Comparing two xml docs with an external dtd Stefan: I am all set with this, thank you very much for your help. Anamika=20 -----Original Message----- From: Stefan Bodewig [mailto:bo...@ap...]=20 Sent: Thursday, May 03, 2007 10:42 AM To: xml...@li...; Majumder, Anamika Subject: Re: [Xmlunit-general] Comparing two xml docs with an external dtd [please keep the list in CC so that the answers get archived] > I have written a class implementing EntityResolver with the > following method: looks good at first glance. > And my testcase looks like the following: My aim is to compare testf > with controlf and the dtd (InfoSettlementResponse.dtd) resides in > the same directory as the xml files. If you are using XMLUnit 1.1 beta, simply use XMLUnit.setControlEntityresolver and XMLUnit.setTestEntitiyResolver and then invoke assertXMLEquals or Diff just as you did in your first code examples. Alternatively you (should work in 1.0 as well) can parse the XML files yourself, while setting the EntityResolver, something like > File controlf =3D new File("C:/Program Files/xmlunit/tests/etc/InfoSettlementResponse_control.xml"); > =20 > DocumentBuilder dbCon =3D XMLUnit.getControlParser(); > OmgeoDTDEntityResolver er =3D new OmgeoDTDEntityResolver(); > dbCon.setEntityResolver(er); Document docCon =3D dbCon.parse(new InputSource(new FileInputStream(controlf))); andd similar for the test document. I.e. you parse your document under the control of the EntityResolver. The parser's going to call back on your resolver when it encounters the DTD's public identifier. See the jaxp docs for more details. After you have Document instances you can use the Diff constructor that accepts org.w3c.dom.Document as arguments. Stefan |