comparing two complex XML in java

105 views Asked by At

I have a requirement where i need to compare two xml's which contains complex objects, I need to compare if there is any changes in xml before and after commit

What will be best and most efficient way to compare, I wont be able to use xmlunit api

 <mf>
     <df dimId="7" memberOnly="true">
         <ml>
            <m>
                  <value>2458989</value>
                  <hid>10005</hierarchyId>
                  <lid>51</levelId>
                  <display>5/19/20</displayValue>
             </m>
         </ml>
      </df>
   </mf>

Tried this
DOMParser parser = new DOMParser();

    parser.parse(new StringReader(cd));
    XMLDocument xmlDocument1 = parser.getDocument();
    parser.parse(new StringReader(fromDb));
    XMLDocument xmlDocument2 = parser.getDocument();
    //XMLCompare xmlDiff=new XMLCompare();
    XMLDiff xmlDiff = new XMLDiff();
    xmlDiff.setDocuments(xmlDocument1, xmlDocument2);
    xmlDiff.diff() //always returns true eventhough if we dont have any differences.

I wont be able to use xmlUnit api, please help me in fixing this

<memberFilters>
      <dimensionFilter dimId="7" memberOnly="true">
         <memberList>
            <member>
               <value>2458989</value>
               <hierarchyId>10005</hierarchyId>
               <levelId>51</levelId>
               <displayValue>5/19/20</displayValue>
            </member>
         </memberList>
         <criteria>
            <preSelectedMemberList>
               <member>
                  <value>2458989</value>
                  <hierarchyId>10005</hierarchyId>
                  <levelId>51</levelId>
                  <displayValue>5/19/20</displayValue>
               </member>
            </preSelectedMemberList>
            <Criterion>
               <selection>Replace</selection>
               <criterionByLevel>
                  <hierarchyId>10005</hierarchyId>
                  <levelId>10009</levelId>
                  <levelName>Period</levelName>
               </criterionByLevel>
            </Criterion>
            <Criterion>
               <selection>Replace</selection>
               <criterionByMeasure>
                  <hierarchyId>10005</hierarchyId>
                  <levelId>51</levelId>
                  <levelName>Day</levelName>
                  <condition byValue="true" usePercent="false"> 
                     <conditionOp>AND</conditionOp>
                     <measureId>1522</measureId>
                     <measureName>value</measureName>
                     <compareOp>EQ</compareOp>
                     <value>0</value>
                     <roundDecimalDigits>0</roundDecimalDigits>
                  </condition>
               </criterionByMeasure>
            </Criterion>
         </criteria>
      </dimensionFilter>
   </memberFilters>
0

There are 0 answers