2013-05-22 2 views
1

xmlunit을 사용하여 두 텍스트 파일을 비교하고 있습니다. 제어 XML이다 : 나는 및 요소 교체가 XML의 다른 부분에 대해이 비교하고XmlUnit 및 하위 노드

<books> 
    <book> 
     <name>Angels &amp; Demons</name> 
     <isbn>9971-5-0210-0</isbn> 
     <author>Dan Brown</author> 
     <category></category> 
    </book> 
</books> 

.

<books> 
    <book> 
     <isbn>9971-5-0210-0</isbn> 
     <name>Angels &amp; Demons</name> 
     <author>Dan Brown</author> 
     <category></category> 
    </book> 
</books> 

은 diff 객체는 다음과 같은 차이를보고합니다

Expected sequence of child nodes '1' but was '3' - comparing <name...> at /books[1]/book[1]/name[1] to <name...> at /books[1]/book[1]/name[1] 

<name> 경우는 자식 노드 인을 '1', <isbn>가 자식 노드를하지 않을 것 '2'?

+0

. \t \t ** XMLUnit.setIgnoreWhitespace (true); ** 자식 노드의 예상 시퀀스 '0'을 사용했지만 '1'이었습니다./struct [1]/int [1]에서 을 비교했습니다./struct [1]/int [1]'에있는 까지 – timmy

답변

0

XmlUnit은 xml의 캐리지 리턴을 자식 노드로 계산하는 것으로 보입니다. 다음 XMLUnit.setIgnoreWhitespace (true)를 설정합니다. 아이 노드 '0'의 예상 시퀀스의보다 직관적 인 결과를하는 듯했으나 '1'입니다 - 위해 XMLUnit 2.X 버전에

1

<int...> at /struct[1]/int[1] to <int...> at /struct[1]/int[1]을 비교 한 다음 위해 XMLUnit의 2.XX 버전에 대한

의 위해 XMLUnit을. setIgnoreWhitespace (true)는 더 이상 적용되지 않습니다. 이제 DiffBuilder.ignoreWhitespace()를 추가하여 DiffBuilder에 "공백 무시"를 직접 추가 할 수 있습니다. XMLS 주장에 대한

Diff diffXml =DiffBuilder.compare(expectedXml).withTest(actualXml).normalizeWhitespace().checkForSimilar().build(); 

는 예를 들어 유사하다. 수행

MatcherAssert.assertThat(diffXml.toString(), is("[identical]")); 

를 2.x으로하는 1.x의 사이의 변경 사항에 대한 furhter 정보를 참조 : 위해 XMLUnit는 자식 노드와 XML에 캐리지 리턴을 기대하고있다 것 같다 https://github.com/xmlunit/user-guide/wiki/Migrating-from-XMLUnit-1.x-to-2.x