cancel
Showing results for 
Search instead for 
Did you mean: 

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

Occasional Contributor

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 xmlnsSmiley FrustratedOAP-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

7 REPLIES 7
Highlighted
Community Hero

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

Based on your request, it appears that you have tried something. Please show that which will help.


Regards,
Rao.
Highlighted
Occasional Contributor

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

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.

 

Highlighted
Community Hero

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

What happened when you tried the code from above git link ?


Regards,
Rao.
Highlighted
Community Hero

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

By the way, if you provide sample data (need not be the same, but same xml structure), that would be helpful.


Regards,
Rao.
Highlighted
Occasional Contributor

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

@nmrao When I tried from above git link, I can able to Ignore/Skip nodes and attributes but not able to skip Header and Body lines.

 

Highlighted
Community Hero

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

Then only body should be compared instead of entire message.


Regards,
Rao.
Highlighted
Occasional Contributor

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

Sure, Thank you!