XML : XMLUnit, can i ignore one attribut value AND ignore element order

modele.XML

  <?xml version='1.0' encoding='UTF-8'?>  <MyFile fileId="1" nbrItems="3">      <MyElement Date="2015-12-08T17:22:56+01:00" status="ACTIVE" Attribut1="testintegrationEF133" Attribut2="MerryChristmas"></MyElement>      <MyElement Date="2015-12-08T17:22:56+01:00" status="ACTIVE" Attribut1="testintegrationEF134" Attribut2="MerryChristmas"></MyElement>      <MyElement Date="2015-12-08T17:22:56+01:00" status="ACTIVE" Attribut1="testintegrationEF135" Attribut2="MerryChristmas"></MyElement>  </MyFile >    

toCheck.xml

  <?xml version='1.0' encoding='UTF-8'?>  <MyFile fileId="1" nbrItems="3">      <MyElement Date="3015-12-08T17:22:56+01:00" status="ACTIVE" Attribut1="testintegrationEF135" Attribut2="MerryChristmas"></MyElement>      <MyElement Date="3015-12-08T17:22:56+01:00" status="ACTIVE" Attribut1="testintegrationEF134" Attribut2="MerryChristmas"></MyElement>      <MyElement Date="3015-12-08T17:22:56+01:00" status="ACTIVE" Attribut1="testintegrationEF133" Attribut2="MerryChristmas"></MyElement>  </MyFile >    

My first problem was to ignore the Attribut "Date" :

  • I solved it by using Regex and an overriding of DifferenceListener

The second problem was the order of my elements "MyElement" :

  • I solved it by using overrideElementQualifier(new ElementNameAndAttributeQualifier());

BUT, when I want to do this two "tricks" at the same times i got this error :

Expected attribute value 'testintegrationEF133' but was 'testintegrationEF134'...

My test :

  public void testXmlDiffs( File pathFileToCheck) throws MyException, SAXException, IOException  {          try{                final String[] fileType = pathFileToCheck.getName().split(SEPARATOR);              final InputStreamReader fileModele = findXmlModele(fileType[1]);              final String pathFileToCheck2 = BUNDLE.getString("paths.in").concat(pathFileToCheck.getName());                if (fileModele == null){                  logFichierIntrouvable(fileType[1], pathFileToCheck);                              }              else{                  Reader frModele = null;                  InputStreamReader frToCheck = null;                  frToCheck = new InputStreamReader(new FileInputStream(pathFileToCheck2), UTF_8_ENCODING);                  frModele = fileModele;                    XMLUnit.setIgnoreWhitespace(true);                  XMLUnit.setNormalize(true);                  XMLUnit.setNormalizeWhitespace(true);                  XMLUnit.setIgnoreDiffBetweenTextAndCDATA(true);                  XMLUnit.setIgnoreAttributeOrder(true);                  XMLUnit.setCompareUnmatched(false);                    Diff diff = new Diff(frModele, frToCheck);                    diff.overrideElementQualifier(new ElementNameAndAttributeQualifier());                  diff.overrideDifferenceListener(new SuperListener());                   logResultOk(fileType[1], diff , pathFileToCheck, startTime);              }          }catch(final Exception e) {              throw e;          }      }    

If you have any idee or want more informations you can ask me :-)

thank you

No comments:

Post a Comment