Forum Discussion

PrathapR's avatar
PrathapR
Frequent Contributor
5 years ago

How to skip/ignore Envelope & Header when comparing two Soap(XML) responses

Hi all,

 

I'm trying to compare and find the differences between two soap(XML) responses usning groovy (help of xmlunit or some other approaches),  I can able to do partially(Nodes and attributes) but I cannot able to skip intial/last lines(Header and Body). Would like to skip those as per requirement, if those are not equal as well.

 

Response1:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>

************** (Nodes and Attributes, I can able to comare)

</soapenv:Body>
</soapenv:Envelope>

 

Response2:

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header/>
<SOAP-ENV:Body>

************** (Nodes and Attributes, I can able to comare)

</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

 

 

Please help me if anyone have any idea.

 

Thanks in advance

  • nmrao's avatar
    nmrao
    Champion Level 3
    Based on your request, it appears that you have tried something. Please show that which will help.
    • PrathapR's avatar
      PrathapR
      Frequent Contributor

      Thank you for your response nmrao  ,

      Used below code

      resXML1 = xmlParser.parse("C:\\TestCase_TC1_JS.xml")
      resXML2 = xmlParser.parse("C:\\TestCase_TC2_KS.xml")
      resXML11 = XmlUtil.serialize(resXML1)
      resXML22 = XmlUtil.serialize(resXML2)

      //Compare two Responses
      //assert(resXML22 == resXML11) : "Res1 Doesn't Match with Res2"


      diff = new Diff(resXML22, resXML11)

      XMLUnit.setIgnoreComments(Boolean.TRUE);
      XMLUnit.setNormalizeWhitespace(Boolean.TRUE); //Ignore WhiteSpace
      XMLUnit.setIgnoreDiffBetweenTextAndCDATA(Boolean.TRUE); //Ignore Text and CDATA
      XMLUnit.setIgnoreAttributeOrder(Boolean.TRUE); //Ignore Attribute Order

      try {
      log.info (diff.similar());
      log.info(diff.identical());
      DetailedDiff detDiff = new DetailedDiff(diff);

      detDiff.overrideElementQualifier(new ElementNameAndAttributeQualifier());
      detDiff.overrideElementQualifier(new RecursiveElementNameAndTextQualifier());
      List differences = detDiff.getAllDifferences();
      for (Object object : differences) {
      Difference difference = (Difference)object;
      log.info("***********************");
      log.error(difference);
      log.info("***********************");
      }

      } catch (SAXException e) {
      e.printStackTrace();
      } catch (IOException e) {
      e.printStackTrace();
      }

       

      Also used/tried  from your git code

      https://github.com/nmrao/groovyScripts/blob/master/compare/CompareWithIgnoreElements.groovy

       

      but in this I can able to ignore nodes and attributes. not bale to do the above mentioned lines.

       

      • nmrao's avatar
        nmrao
        Champion Level 3
        What happened when you tried the code from above git link ?