Source sample data : Took the sample xml from (v=vs.85), made 2 xmls from it and modified it to generate differences as required.Ĥ. org.xmlunit xmlunit-core 2.2.1 org.xmlunit xmlunit-matchers 2.2.1 Solution approach - XMLUnit to the rescueĪfter doing some research, we zeroed on XMLUnit(version 2.2.1) Support the changes without (or minimum code change).Override the comparison logic - to ignore certain elements and to elements with differences below certain configurable threshold.If no mapping element was found, it was reported as missing in one environment. If a mapping element found by criteria 1 on other side, use it else moved to next and so on. We also needed some solution which supports a chain of mapping criterion. Define mapping criteria configurable - to define how to identify the elements to be compared.We were looking for some solution which enables us to reduce the custom code and make solution of below requirements configurable and free from XSD. JAXB based utility was working fine till now but with each change in structure (even very small ), we need to make change in the utility and build new version. There are frequent introduction of new report types and changes in the existing report structures. The type and number of reports has risen significantly off late. change the custom java comparison code to support the comparison of the new structures.Add above jar to the classpath of the utility.Generate new java classes (and jars )based on the updated XSDs.We had to follow below steps to support any introduction of new report or addition of new elements in the existing report or any change in the existing structure. Then there was another custom code to write the differences to the html report. For few numeric fields, we had to define tolerance as well to ignore the difference below certain level. Then there was custom code to compare these elements field by field. In some cases we had to include the child elements (let’s say address ) to identify the elements to be compared. For example, we had to define that employees will be uniquely identified by their names but departments will be identified by both name and codes. We had written custom java code for grouping ( to map the elements on the both sides to be compared ). JAXBContext jaxbContext = JAXBContext.newInstance( Employee.class ) Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller() Employee employee = (Employee) jaxbUnmarshaller.unmarshal( xmlSource ) The code for unmarshalling the reports was like this.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |