Hi Chetan

There are some demo programs in src/samples that demonstrate the use of
XPath, in particular LinkChecker finds all <a> elements in a document and
XPathGrep is a kind of grep-like tool that uses XPath on XML documents.

There's a quick overview here:-

http://dom4j.org/guide.html
http://dom4j.org/guide.html#Powerful%20Navigation%20with%20XPath

If you need any help learning XPath there's a great tutorial here:-

http://www.zvon.org/xxl/XPathTutorial/General/examples.html

If you wish to compare 2 documents or any other nodes (Elements, Attributes
etc) then there is a utility class called NodeComparator in the
org.dom4j.util package.

http://dom4j.org/apidocs/org/dom4j/util/NodeComparator.html

It implements the java.util.Comparator interface so can be used with all the
Java Collections Framework classes.

http://java.sun.com/j2se/1.3/docs/api/java/util/Comparator.html

To use it explicitly you can use the compare() method such as:-

    SAXReader reader = new SAXReader();
    Document doc1 = reader.read( "foo.xml" );
    Document doc2 = reader.read( "bar.xml" );

    NodeComparator comparator = new NodeComparator();
    if ( comparator.compare( doc1, doc2 ) == 0 ) {
        System.out.println( "The documents are equal" );
    }
    else {
        System.out.println( "Documents are not equal" );
    }

As you can see from the JavaDoc the NodeComparator can compare document
fragments or individual nodes too (such as Elements or Attributes).


James
----- Original Message -----
From: "Chetan Sanghi" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Tuesday, July 03, 2001 8:51 PM
Subject: [dom4j-user] From Chetan Sanghi


> Hi
>
> I want to write a jUnit test case for comparing two XML documents and I
want
> to use dom4j API for its XPath advantages. It will be great if somebody
can
> let me know where to start like some detailed examples of dom4j using
XPath
> features and comparing two XML documents.
>
> --Chetan
> _________________________________________________________________
> Get your FREE download of MSN Explorer at http://explorer.msn.com
>
>
> _______________________________________________
> dom4j-user mailing list
> [EMAIL PROTECTED]
> http://lists.sourceforge.net/lists/listinfo/dom4j-user
>


_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com


_______________________________________________
dom4j-user mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/dom4j-user

Reply via email to