Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9280181
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T17:48:33+00:00 2026-06-18T17:48:33+00:00

This code: import org.custommonkey.xmlunit.Diff; String result = <ns1:Square xsi:type=\ns1:Shape\ xmlns:ns1=\http://example.com/\ xmlns:xsi=\http://www.w3.org/2001/XMLSchema-instance\/>; String correct =

  • 0

This code:

import org.custommonkey.xmlunit.Diff;

String result = "<ns1:Square xsi:type=\"ns1:Shape\" xmlns:ns1=\"http://example.com/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"/>";
String correct = "<ns2:Square xsi:type=\"ns2:Shape\" xmlns:ns2=\"http://example.com/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"/>";

Diff diff = new Diff(result, correct);
System.out.println("diff:" + diff);
System.out.println("diff.similar(): " + diff.similar());

results in:

diff: org.custommonkey.xmlunit.Diff
[not identical] Expected namespace prefix 'ns1' but was 'ns2' - comparing <ns1:Square...> at /Square[1] to <ns2:Square...> at /Square[1]

[different] Expected attribute value 'ns1:Shape' but was 'ns2:Shape' - comparing <ns1:Square xsi:type="ns1:Shape"...> at /Square[1]/@type to <ns2:Square xsi:type="ns2:Shape"...> at /Square[1]/@type

diff.similar(): false

I would expect diff.similar() to be true.
or is there a reason why it is false? or it is a bug?

it returns true if I remove the xsi:type info.

any idea how to fix it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T17:48:34+00:00Added an answer on June 18, 2026 at 5:48 pm

    XMLUnit doesn’t understand xsi type . It does a simple string comparison for attribute value.

    Implements a custom DifferenceListener do the trick

        final Diff d = new Diff(result, correct);
        d.overrideDifferenceListener(new DifferenceListener() {
    
            public int differenceFound(Difference difference) {
    
                final Node controlNode = difference.getControlNodeDetail().getNode();
                final Node testNode = difference.getTestNodeDetail().getNode();
                if (difference.getId() == DifferenceConstants.ATTR_VALUE_ID
                    && isXSIType(controlNode) && isXSIType(testNode)) {
                    if (getNameSpaceFromPrefix(controlNode).compareTo(getNameSpaceFromPrefix(testNode)) != 0) {
                        return RETURN_ACCEPT_DIFFERENCE;
                    }
                    String withoutPrefixControl = getNameWithoutPrefix(controlNode);
                    String withoutPrefixTest = getNameWithoutPrefix(testNode);
    
                    if (withoutPrefixControl.compareTo(withoutPrefixTest) == 0) {
                        return RETURN_IGNORE_DIFFERENCE_NODES_IDENTICAL;
                    }
                }
                return RETURN_ACCEPT_DIFFERENCE;
            }
    
            boolean isXSIType(org.w3c.dom.Node node) {
                return node.getNodeType() == Node.ATTRIBUTE_NODE &&
                    node.getLocalName().compareTo("type") == 0 &&
                    node.getNamespaceURI() == "http://www.w3.org/2001/XMLSchema-instance";
            }
    
            private String getNameSpaceFromPrefix(Node node) {
                final int beginIndex = node.getNodeValue().indexOf(":");
                if (beginIndex == -1) {
                    return "";
                }
                return node.lookupNamespaceURI(node.getNodeValue().substring(0, beginIndex));
            }
    
            private String getNameWithoutPrefix(Node controlNode) {
                final int beginIndex = controlNode.getNodeValue().indexOf(":");
                if (beginIndex == -1) {
                    return controlNode.getNodeValue();
                }
                return controlNode.getNodeValue().substring(beginIndex);
            }
    
            public void skippedComparison(org.w3c.dom.Node node, org.w3c.dom.Node node1) {
    
            }
        });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using this code : import org.codehaus.jackson.map.ObjectMapper; ObjectMapper objectMapper = new ObjectMapper(); String str =
I used this code in my Android application: import org.apache.http.client.methods.HttpPost; ... HttpClient httpclient =
Try this code - import java.io.StringReader; public class StringReaderTest { public static void main(String[]
I have this code: import re def doReplace(toReplace): i = 1 def chapterReplacer(_): result
Consider this code: import java.util.Collections; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.core.userdetails.User; public class SecureStuff { @PreAuthorize(#user.password
I have this code: package org.optimization.geneticAlgorithm; import org.optimization.geneticAlgorithm.selection.Pair; public abstract class Chromosome implements Comparable<Chromosome>
I have used this code import org.apache.commons.net.ftp.FTPClient; import java.io.FileInputStream; import java.io.IOException; public class FTPClientExample
I configure ssl on jetty. I am using this code: import org.mortbay.jetty.security.SslSocketConnector; . .
I have found this code sample import org.apache.http.params.CoreProtocolPNames; import org.apache.http.util.EntityUtils; public class PostFile {
Consider this code: import socket store = [] scount = 0 while True: scount+=1

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.