久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

使用 XMLUnit 2.X 比較 xml 文件時忽略特定節(jié)點的特

Ignoring a particular attribute of a specific Node while comparing xml files using XMLUnit 2.X(使用 XMLUnit 2.X 比較 xml 文件時忽略特定節(jié)點的特定屬性)
本文介紹了使用 XMLUnit 2.X 比較 xml 文件時忽略特定節(jié)點的特定屬性的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

我有兩個 XML 文件:

I have two XML files:

<!------------------------File1--------------------------------->
    <note id="ignoreThisAttribute_1">
      <to>Experts</to>
      <from>Matrix</from>
      <heading id="dontIgnoreThisAttribute_1">Reminder</heading>
      <body>Help me with this problem</body>
    </note>

<!------------------------File2--------------------------------->
    <note id="ignoreThisAttribute_2">
      <to>Experts</to>
      <from>Matrix</from>
      <heading id="dontIgnoreThisAttribute_2">Reminder</heading>
      <body>Help me with this problem</body>
    </note>

在比較這兩個文件時,我必須忽略 Node:note 的屬性:id.

I have to ignore the attribute:id of Node:note while comparing these two files.

我正在使用 DiffBuilder:

Diff documentDiff = DiffBuilder.compare(srcFile).withTest(destFile).build()

大多數(shù)在線解決方案建議實現(xiàn) DifferenceEvaluator:

Most online solutions suggested implementing DifferenceEvaluator:

也試過了,但這會忽略所有具有屬性 id 的節(jié)點,而我想忽略來自特定節(jié)點的屬性:

Tried that as well, but this ignores all nodes with attribute id, whereas I want to ignore an attribute from a specific node:

public class IgnoreAttributeDifferenceEvaluator implements DifferenceEvaluator {
        private String attributeName;
        public IgnoreAttributeDifferenceEvaluator(String attributeName) {
            this.attributeName = attributeName;
        }

        @Override
        public ComparisonResult evaluate(Comparison comparison, ComparisonResult outcome) {
            if (outcome == ComparisonResult.EQUAL)
                return outcome;
            final Node controlNode = comparison.getControlDetails().getTarget();


            System.out.println(controlNode.getNodeName());
            if (controlNode instanceof Attr) {
                Attr attr = (Attr) controlNode;
                if (attr.getName().equals(attributeName)) {
                    return ComparisonResult.EQUAL;
                }
            }
            return outcome;
        }
    }

在我的測試類中調(diào)用方法:

Calling method in my Test class:

final Diff documentDiff = DiffBuilder.compare(src).withTest(dest)
.withDifferenceEvaluator(new IgnoreAttributeDifferenceEvaluator("id"))
.build();

有人可以建議我使用 XMLUnit 2.x 實現(xiàn)這一目標的方法嗎XMLUnit 的新手,因此請?zhí)峁┫鄳?yīng)的幫助.

Can someone suggest me a way I can achieve this using XMLUnit 2.x New to XMLUnit so please help accordingly.

提前致謝.

推薦答案

如果你真的想要,你可以使用 DifferenceEvaluator.除了屬性本身的名稱之外,您所要做的就是測試 Attr 的所有者元素"名稱的名稱.

You could use a DifferenceEvaluator if you really wanted to. All you'd have to do was testing the name of the Attr's "owner element"'s name in addition to the name of the attribute itself.

但 XMLUnit 2.x 對此提供了不同的解決方案:AttributeFilter.代碼與您已經(jīng)獲得的 DifferenceEvaluator 不會有太大不同,但您不會混淆關(guān)注點.

But XMLUnit 2.x offers a different solution to this: AttributeFilter. The code won't be that different from the DifferenceEvaluator you've already got, but you won't be mixing concerns.

class IgnoreNoteId implements Predicate<Attr> {

    public boolean test(Attr attr) {
        return !("note".equals(attr.getOwnerElement().getNodeName())
            && "id".equals(attr.getNodeName()));
    }
}

使用 Java8 時,在 withAttributeFilter 中使用 lambda 甚至更短.

or even shorter with a lambda in withAttributeFilter when using Java8.

這篇關(guān)于使用 XMLUnit 2.X 比較 xml 文件時忽略特定節(jié)點的特定屬性的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

Upload progress listener not fired (Google drive API)(上傳進度偵聽器未觸發(fā)(Google 驅(qū)動器 API))
Save file in specific folder with Google Drive SDK(使用 Google Drive SDK 將文件保存在特定文件夾中)
Google Drive Android API - Invalid DriveId and Null ResourceId(Google Drive Android API - 無效的 DriveId 和 Null ResourceId)
Google drive api services account view uploaded files to google drive using java(谷歌驅(qū)動api服務(wù)賬戶查看上傳文件到谷歌驅(qū)動使用java)
Google Drive service account returns 403 usageLimits(Google Drive 服務(wù)帳號返回 403 usageLimits)
com.google.api.client.json.jackson.JacksonFactory; missing in Google Drive example(com.google.api.client.json.jackson.JacksonFactory;Google Drive 示例中缺少)
主站蜘蛛池模板: 一级片aaa | 在线观看免费av网 | 国产专区在线 | 久久精品色视频 | 久久久久久国产精品 | 日韩久久在线 | 亚洲国产成人精品久久久国产成人一区 | 成人在线观| 亚洲精品不卡 | 在线伊人网 | 欧美在线一区二区视频 | 中文字幕一区二区三区日韩精品 | 精品久久影院 | 亚洲欧美一区二区三区在线 | 国产精品视频免费观看 | 国产欧美日韩精品一区二区三区 | av 一区二区三区 | 亚洲二区在线 | 国产精品综合 | 草草网 | 亚洲国产高清高潮精品美女 | 福利网站导航 | 日日摸日日碰夜夜爽亚洲精品蜜乳 | av大片在线观看 | 久久视频免费观看 | 亚洲第一区久久 | 国产美女在线精品免费 | 日本黄色影片在线观看 | 四虎影院在线观看av | 欧美v在线观看 | 精品亚洲第一 | 一级毛片网 | 国产一区二区三区免费 | 欧美日韩成人一区二区 | 国产综合区 | 羞羞色在线观看 | 视频一区中文字幕 | 午夜精品三区 | 成人免费小视频 | 国产激情视频在线观看 | 欧美淫片|