Click here to Skip to main content
15,888,401 members
Home / Discussions / Java
   

Java

 
Questionhow to do it Pin
zahidul hasan21-Mar-21 21:07
zahidul hasan21-Mar-21 21:07 
AnswerRe: how to do it Pin
Richard MacCutchan21-Mar-21 22:48
mveRichard MacCutchan21-Mar-21 22:48 
QuestionHow to update nested Array in Spring boot mongodb Pin
devTUapp15-Mar-21 7:33
devTUapp15-Mar-21 7:33 
QuestionWhat should I I learn with Java? Pin
Member 1509539610-Mar-21 3:02
Member 1509539610-Mar-21 3:02 
AnswerRe: What should I I learn with Java? Pin
NotTodayYo10-Mar-21 3:40
NotTodayYo10-Mar-21 3:40 
AnswerRe: What should I I learn with Java? Pin
Richard MacCutchan10-Mar-21 4:06
mveRichard MacCutchan10-Mar-21 4:06 
QuestionPass variable to HttpURLConnection Pin
xoduhuko10-Mar-21 2:40
xoduhuko10-Mar-21 2:40 
QuestionHow to compare two similar xml documents ignoring node text values by using XMLUnit? Pin
mr.pakapun1-Mar-21 17:32
mr.pakapun1-Mar-21 17:32 
I have two different XML documents below and please note that they are having the same basic structure (schema).

Source XML

XML
<root>
<name>String</name>
<description>String</description>
</root>


Test XML

XML
<root>
<name>Test</name>
<description></description> <!-- it is an empty node -->
</root>


And I build this snippet function to compare those two XML documents.

Java
import org.custommonkey.xmlunit.Diff;
import org.custommonkey.xmlunit.Difference;
import org.custommonkey.xmlunit.IgnoreTextAndAttributeVal uesDifferenceListener;
import org.custommonkey.xmlunit.XMLUnit;

public static void main(String args[]) throws FileNotFoundException,
SAXException, IOException, ParserConfigurationException, XPathExpressionException {

String strSource = "<root><name>String</name><description>String</description></root>";
String strTest = "<root><name>Test</name><description></description></root>";

Document docSource = stringToXMLDocument(strSource);
Document docTest = stringToXMLDocument(strTest);

boolean result = isMatched(docSource, docTest);
if(result){
System.out.println("Matched!");
}else{
System.out.println("Un-matched!");
}
}
public static boolean isMatched(Document xmlSource, Document xmlCompareWith) {
XMLUnit.setIgnoreWhitespace(true);
XMLUnit.setIgnoreComments(true);
XMLUnit.setIgnoreAttributeOrder(true);

XMLUnit.setNormalizeWhitespace(true);
XMLUnit.setIgnoreDiffBetweenTextAndCDATA(true);

Diff myDiff = new Diff(xmlSource, xmlCompareWith);
myDiff.overrideDifferenceListener(new IgnoreTextAndAttributeValuesDifferenceListener());
return myDiff.similar();
}

public static Document stringToXMLDocument(String str) throws ParserConfigurationException, SAXException, IOException{
DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
docBuilderFactory.setNamespaceAware(true);

DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
Document document = docBuilder.parse(new InputSource(new StringReader(str)));

return document;
}



And here is the Maven dependency

XML
<dependency>
<groupId>xmlunit</groupId>
<artifactId>xmlunit</artifactId>
<version>1.6</version>
</dependency>


I am expecting those two XML documents are the same, but the function always returns false. Are there any ways that I can ignore the node text value when comparing two XML structures? As you can see, I already used IgnoreTextAndAttributeValuesDifferenceListener, but I still got the problem.
SuggestionRe: How to compare two similar xml documents ignoring node text values by using XMLUnit? Pin
Richard MacCutchan1-Mar-21 21:22
mveRichard MacCutchan1-Mar-21 21:22 
QuestionLicense key generator Pin
keznet lisimati27-Feb-21 0:27
keznet lisimati27-Feb-21 0:27 
QuestionDefault My program does not find the file MyFriends.txt Pin
zorapulo11-Feb-21 16:25
zorapulo11-Feb-21 16:25 
AnswerRe: Default My program does not find the file MyFriends.txt Pin
Richard MacCutchan11-Feb-21 21:24
mveRichard MacCutchan11-Feb-21 21:24 
Questionhow to write result in excel using java selenium. Pin
Member 1393850211-Feb-21 2:46
Member 1393850211-Feb-21 2:46 
AnswerRe: how to write result in excel using java selenium. Pin
Richard MacCutchan11-Feb-21 3:01
mveRichard MacCutchan11-Feb-21 3:01 
Generalhow to write result in excel using java selenium. Pin
Member 1393850211-Feb-21 2:32
Member 1393850211-Feb-21 2:32 
GeneralRe: how to write result in excel using java selenium. Pin
OriginalGriff11-Feb-21 2:50
mveOriginalGriff11-Feb-21 2:50 
GeneralRe: how to write result in excel using java selenium. Pin
Cp-Coder11-Feb-21 2:51
Cp-Coder11-Feb-21 2:51 
JokeRe: how to write result in excel using java selenium. Pin
Slacker00711-Feb-21 3:14
professionalSlacker00711-Feb-21 3:14 
GeneralRe: how to write result in excel using java selenium. Pin
Richard MacCutchan11-Feb-21 3:34
mveRichard MacCutchan11-Feb-21 3:34 
GeneralRe: how to write result in excel using java selenium. Pin
Marc Clifton11-Feb-21 3:49
mvaMarc Clifton11-Feb-21 3:49 
QuestionJAVA PROGRAMMING Pin
Member 150686089-Feb-21 2:02
Member 150686089-Feb-21 2:02 
AnswerRe: JAVA PROGRAMMING Pin
Richard MacCutchan9-Feb-21 2:49
mveRichard MacCutchan9-Feb-21 2:49 
QuestionBarrons Ap Computer Science A / question on compound boolean Pin
Ap_noob12-Jan-21 11:45
Ap_noob12-Jan-21 11:45 
AnswerRe: Barrons Ap Computer Science A / question on compound boolean Pin
Richard MacCutchan12-Jan-21 21:40
mveRichard MacCutchan12-Jan-21 21:40 
QuestionConvert string array to integer without using loop? Thanks Azbilegt Chuluunbat Pin
Azbilegt Chuluunbat30-Dec-20 6:48
Azbilegt Chuluunbat30-Dec-20 6:48 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.