We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Compare two Nodes of same Document after reloading

Hi there,

Is there a chance, to compare the same Node of a Document after “reloading” it and get true as compare result?

Here is a plumb Example, what i want to do…:


Document tmpDoc1 = new Document(tmpPath);
Node tmpNode1 = tmpDoc1.getChild(NodeType.RUN, 1, true);
//DO SOME STUFF on tmpDoc1 without saving on same location again

Document tmpDoc2 = new Document(tmpPath);
Node tmpNode2 = tmpDoc2.getChild(NodeType.RUN, 1, true);

// I need a compare with true as result here…
System.out.println("Compare: " + tmpNode1.equals(tmpNode2));


I’m working with the latest version of Aspose.Words for Java…

Thanks in advance
tmd

Hi there,
Is there a chance, to compare the same Node of a Document after "reloading" it and get true as compare result?

Here is a plumb Example, what i want to do...:


Document tmpDoc1 = new Document(tmpPath);
Node tmpNode1 = tmpDoc1.getChild(NodeType.RUN, 1, true);
//DO SOME STUFF on tmpDoc1 without saving on same location again

Document tmpDoc2 = new Document(tmpPath);
Node tmpNode2 = tmpDoc2.getChild(NodeType.RUN, 1, true);

// I need a compare with true as result here....
System.out.println("Compare: " + tmpNode1.equals(tmpNode2));


I'm working with the latest version of Aspose.Words for Java..

@admins: this is a second post, as i by mistake made the first one private and wasn't able to remove private flag... :(

Thanks in advance
tmd

Hi Robert,


Thanks for your inquiry. Currently, Aspose.Words can compare two documents. I think, you can implement the following workflow to meet this requirement.

Document tmpDoc1 = new Document(getMyDir() + “input.docx”);
Node tmpNode1 = tmpDoc1.getChild(NodeType.RUN, 1, true);

Document tmpDoc2 = new Document(getMyDir() + “input.docx”);
Node tmpNode2 = tmpDoc2.getChild(NodeType.RUN, 1, true);

// Create a blank document from original tmpDoc1 document and
// just import one Node to it that you want to compare
Document word1 = (Document) tmpDoc1.deepClone(false);
word1.ensureMinimum();
word1.getFirstSection().getBody().getFirstParagraph().appendChild(
word1.importNode(tmpNode1, true, ImportFormatMode.USE_DESTINATION_STYLES));

// Create a blank document from original tmpDoc2 document and
// just import one Node to it that you want to compare
Document word2 = (Document) tmpDoc2.deepClone(false);
word2.ensureMinimum();
word2.getFirstSection().getBody().getFirstParagraph().appendChild(
word2.importNode(tmpNode2, true, ImportFormatMode.USE_DESTINATION_STYLES));

// Compare these documents using Document.Compare Method
word1.compare(word2, “Awais”, new Date());
// Above method produces changes as number of edit and format revisions Revision.
// If there are no Revisions, it means both are equal
if (word1.getRevisions().getCount() == 0){
System.out.println(“Nodes are equal”);
}
else {
for (Revision rev : word1.getRevisions()) {
System.out.println(rev.getRevisionType());
}
}

Hope, this helps.

Best regards,