title: Java XML files comparison
body: <p>I'm trying to compare 2 XML files using XMLUnit. I tried with the following code in eclipse, I have placed the xml files to be compared in the local directory.</p>
  
  <pre><code>import java.io.FileNotFoundException;
  import java.io.IOException;
  import java.net.URL;
  import java.util.List;
  
  import org.custommonkey.xmlunit.DetailedDiff;
  import org.custommonkey.xmlunit.Diff;
  import org.custommonkey.xmlunit.Difference;
  import org.xml.sax.SAXException;
  
  public class ComparisonTest {
  
  public static void main(String[] args) {
      URL url1 = ComparisonTest.class.getResource("D:/reference.xml");
      URL url2 = ComparisonTest.class.getResource("D:/comparison.xml");
      FileReader fr1 = null;
      FileReader fr2 = null;
      try {
          fr1 = new FileReader(url1.getPath());
          fr2 = new FileReader(url2.getPath());
      } catch (FileNotFoundException e) {
          e.printStackTrace();
      }
  
      try {
          Diff diff = new Diff(fr1, fr2);
          System.out.println("Similar? " + diff.similar());
          System.out.println("Identical? " + diff.identical());
  
          DetailedDiff detDiff = new DetailedDiff(diff);
          List differences = detDiff.getAllDifferences();
          for (Object object : differences) {
              Difference difference = (Difference)object;
              System.out.println("***********************");
              System.out.println(difference);
              System.out.println("***********************");
          }
  
      } catch (SAXException e) {
          e.printStackTrace();
      } catch (IOException e) {
          e.printStackTrace();
      }
  }
  
  }
  </code></pre>
  
  <p>I'm getting an error as </p>
  
  <pre><code>Exception in thread "main" java.lang.NullPointerException
  at com.org.comparison.ComparisonTest.main(ComparisonTest.java:21)
  </code></pre>
  
  <p>I'm not able to figure out why?</p>