on 2021 Jun 23 9:21 AM
Hi 7a519509aed84a2c9e6f627841825b5a , engswee.yeoh
I am trying to find out the difference between two xml files and return the difference tags.
To Achieve this I am storing the xml files in Datastore and to find out the difference I am using the below Groovy script.
import com.sap.gateway.ip.core.customdev.util.Message
//Imports for DataStoreService-class
import com.sap.it.api.asdk.datastore.*
import com.sap.it.api.asdk.runtime.*
/*import org.jdom.Document;
import org.jdom.Element;
import org.jdom.input.SAXBuilder;
import org.jdom.output.XMLOutputter;*/
import org.jdom2.*;
import org.xmlunit.diff.*;
Message processData(Message message)
{
def service = new Factory(DataStoreService.class).getService()
//Check if valid service instance was retrieved
if( service != null) {
//Read data store entry via id
def dsEntry = service.get("MetadataStorage","Metadata")
def result = new String(dsEntry.getDataAsArray())
//message.setBody(body)
def dsEntry1 = service.get("MetadataCurrent","CurrentData")
def result1 = new String(dsEntry1.getDataAsArray())
//message.setBody(body)
DifferenceEngine diff = new DOMDifferenceEngine();
diff.addDifferenceListener(new ComparisonListener() {
public void comparisonPerformed(Comparison comparison, ComparisonResult outcome) {
Assert.fail("found a difference: " + comparison);
}
});
diff.compare(result, result1);
}
// return message
}
Below is the Error I am Getting. Kindly let me know if we are missing anything/ suggest me how to get the difference between two xml files.
Note: I have imported JDOM and XMLUNIT Jar files.Error Detailsjavax.script.ScriptException: java.lang.Exception: java.lang.NullPointerException: Cannot invoke method getDataAsArray() on null object@ line 22 in compareXML.groovy, cause: java.lang.NullPointerException: Cannot invoke method getDataAsArray() on null object
Request clarification before answering.
User | Count |
---|---|
53 | |
6 | |
6 | |
5 | |
5 | |
5 | |
3 | |
3 | |
3 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.