ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dominique Devienne <>
Subject RE: Easily compare two XML files
Date Tue, 20 Aug 2002 14:42:47 GMT
You could use, or write your own DOM-based
equals method for DOM nodes, as I did for testing purposes. Mine is probably
not bug free, and deals with TEXT nodes specially, but it served me OK. Here
the javadoc for it (it's only about 150 lines of code and documentation).

Cheers, --DD

   * Determines whether two DOM nodes are equals.
   * <p>
   * Two nodes are considered equals when they are of the same type,
   * have the same attributes (if any), and the same direct and indirect
   * children (if any). 
   * <p>
   * <em>Note that this method cares about the order of the child
   * elements and attributes, so two documents having the same child
   * but in different order will not be considered equals!</em>
   * <p>
   * <em>Note on the other hand that two nodes need not have the
   * same parents, or belong to the same document, to be equals!</em>
   * <p>
   * <em>Finally, note that child text nodes containing only spaces
   * are ignored, and usually represent indentation in the XML
   * @param  lhs the left-hand-side node to compare.
   * @param  rhs the right-hand-side node to compare.
   * @return <code>true</code> if equals; <code>false</code> otherwise.
   *         Two <code>null</code> nodes are considered equals.
  public static boolean equals(Node lhs, Node rhs) {

-----Original Message-----
From: [] 
Sent: Monday, August 19, 2002 8:05 PM
To: Ant Developers List
Subject: Easily compare two XML files

I have an ant unit test that needs to easily compare two XML files.
I could simply do a standard file comparison, but it would seem a bit more
robust to compare the XML element values instead.

One thought is to make two DOM objects and see if the DOM object has an
appropriate equals method.
I haven't used an XML parser in Java for a year or so, and would like to
avoid spending an hour dragging up the appropriate documentation and
reminding myself of the exact syntax necessary.  Can anyone provide a few
helpers here.  Just knowing where to find documentation for whatever
version of Xerces is in the jar files distributed with Ant would be

To unsubscribe, e-mail:   <>
For additional commands, e-mail: <>

View raw message