Stephan - I have another question. I am trying to compare two xml
documents but would like to 
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 
Sent: Thursday, May 03, 2007 11:18 AM
To: 'Stefan Bodewig'; [email protected]
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 

-----Original Message-----
From: Stefan Bodewig [mailto:[EMAIL PROTECTED] 
Sent: Thursday, May 03, 2007 10:42 AM
To: [email protected]; 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 = new File("C:/Program
Files/xmlunit/tests/etc/InfoSettlementResponse_control.xml");
>        
>         DocumentBuilder dbCon = XMLUnit.getControlParser();
>         OmgeoDTDEntityResolver er = new OmgeoDTDEntityResolver();
>         dbCon.setEntityResolver(er);
          Document docCon = 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

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Xmlunit-general mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/xmlunit-general

Reply via email to