Code snippet for comparing two xml files without using xsd for validating their structure is same ( nodes and arguments should be same. Values of each node/argument can be different).
internalvoidVerifyMessageHaveSimilarStructureOfTemplate(stringinputXml,stringtemplateXml){vardocA=newXmlDocument();vardocB=newXmlDocument();docA.LoadXml(inputXml);docB.LoadXml(templateXml);varisDifferent=DoTheyHaveDiferentStructure(docA.ChildNodes,docB.ChildNodes);log.Info("Result of Checking for difference of Input xml with template is : "+isDifferent.ToString());}privateboolDoTheyHaveDiferentStructure(XmlNodeListxmlNodeListA,XmlNodeListxmlNodeListB){if(xmlNodeListA.Count!=xmlNodeListB.Count)returntrue;for(vari=0;i<xmlNodeListA.Count;i++){varnodeA=xmlNodeListA[i];varnodeB=xmlNodeListB[i];if(nodeA.Attributes==null){if(nodeB.Attributes!=null)returntrue;elsecontinue;}if(nodeA.Attributes.Count!=nodeB.Attributes.Count||nodeA.Name!=nodeB.Name)returntrue;List<string>AttributeNameA=newList<string>();List<string>AttributeNameB=newList<string>();for(varj=0;j<nodeA.Attributes.Count;j++){AttributeNameA.Add(nodeA.Attributes[j].Name);AttributeNameB.Add(nodeB.Attributes[j].Name);// -- If attribute position should be same, then include below as well//var attrA = nodeA.Attributes[j];//var attrB = nodeB.Attributes[j];//if (attrA.Name != attrB.Name) return true;}AttributeNameA.Sort();AttributeNameB.Sort();if(!AttributeNameA.SequenceEqual(AttributeNameB))returntrue;if(nodeA.HasChildNodes&&nodeB.HasChildNodes){returnHaveDiferentStructure(nodeA.ChildNodes,nodeB.ChildNodes);}else{returntrue;}}returnfalse;}