简体   繁体   中英

XMLUnit ignore Order of Elements

I compare two xml files with each other with the help of XMLUnit now if i use this code to compare

@Test
public void testForEquality() throws Exception {
 String xml1 = "<table = "01"><uid></uid></table><table = "02"><uid></uid></table>";
 String xml2 = "<table = "02"><uid></uid></table><table = "01"><uid></uid></table>";
 assertXMLEqual(myControlXML, myTestXML);
 Diff diff = new Diff(myControlXML, myTestXML);
 assertTrue(diff.similar());
}

now it gives me out: Expected attribute value '02' but was '01' but i don't want a difference i want the table id to be unique and only check what the Main-Element in this case:table -> contains if the same table id is seen in the other file.

i allready lookt through simmilar questions but they did not helped me out.

You need to tell XMLUnit which rules to apply to identify the table elements it should match with each other. You do so by configuring an ElementQualifier - in your case you will want to use the built-in ElementNameAndAttributeQualifier passing the identifying attribute's name as constructor argument.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM