1

次のように2つのXMLドキュメントがあります

XML1 :

<root>
<element>
<attributes>
<a>1</a>
<b>y</b>
<c>n</c>
<attribute>
<attributes>
<a>2</a>
<b>j</b>
<c>m</c>
<attribute>
<attributes>
<a>3</a>
<b>y</b>
<c>n</c>
<attribute>
<attributes>
<a>4</a>
<b>y</b>
<c>n</c>
<attribute>
<element>
<element2>
</element2>
</root>

**XMl2**:
<root>
<element>
<attributes>
<a>1</a>
<b>y</b>
<c>n</c>
<attribute>
<attributes>
<a>3</a>
<b>y</b>
<c>n</c>
<attribute>
<attributes>
<a>4</a>
<b>y</b>
<c>n</c>
<attribute>
<element>
<element2>
</element2>
</root>

最初の子要素のテキストが両方の XML で等しい<attribute>場合にのみ、子要素 を比較したい<a>

たとえば、XML1 のwhere = 3 と XML2 の<attribute>where = 3 を比較したいとします。<a><attribute><a>

現在、以下のコードを使用しています。

Diff myDiff=null;

    DifferenceListener myDifferenceListener = new IgnoreTextAndAttributeValuesDifferenceListener();

    try {
        myDiff = new Diff(expected,actual);
        myDiff.overrideDifferenceListener(myDifferenceListener);
    } catch (SAXException | IOException e) {
        e.printStackTrace();
    }

   DetailedDiff myDiffd = new DetailedDiff(myDiff);
    List<Difference> allDifferences = myDiffd.getAllDifferences();

これは私に間違った比較を与えています。<attribute>where = 3 が XML にない場合<a>、このノードと次のすべてのノードが不一致として表示されます。しかし、このノードだけが不一致として欲しいです。

どんな助けでも大歓迎です。

4

0 に答える 0