0
<listing>
  <items>
  <item dept="acct" tag="12223">
    <name>laser printer</name>
    <area>common</area>
  </item>
  <item dept="acct" tag="65436">
    <name>table, round 1m</name>
    <area>storage</area>
  </item>
  </items>

  <locations>
  <building dept="recptn" >
     <wing>main</wing>
     <floor area="storage">1</floor>
     <floor area="common">1</floor>
     <floor area="office">2</floor>
  </building>
  
  </locations>
  
</listing>

I want to compare only part of the XML file for example i want to compare only the items of both xml files ignoring all other nodes.I believe i can achieve this using node-filter, but if there are a lot of nodes (as i was given a XML file which has 33K lines with lots of nodes),what will be the best way to compare those XML files (1) select a piece of xml and compare? (2) compare both files by ignoring nodes.

        Diff diff = DiffBuilder.compare(expectedSource).withTest(actualSource).checkForSimilar()
                .withNodeMatcher(new DefaultNodeMatcher(ElementSelectors.byXPath("//listing/items",
                        ElementSelectors.byNameAndAttributes("Name"))))
                .build();
Ankit
  • 1
  • Be careful, XML is case sensitive: `byNameAndAttributes("Name")`. Element on XML is `name` – LMC Feb 22 '23 at 18:18

0 Answers0