Skip to content

How do I compare two XML strings

This example demonstrates comparing two XML strings within the context of an automated test in execution. 

In the solution shown below, the two XML strings are stored into the variables using "store" command and compared using "xmlCompare" command. The command returns "1" if both XML strings are similar else it returns "0".

Note: The notation to reuse the value of the variable in Worksoft SaaS is ${<Variable Name>}.

Solution:

# Command Target Value
Store the XML string 1 in a variable
1 store <insurance><age>45</age><income>20000</income><zipcode>08817</zipcode><result>You are eligible for a subsidy.</result></insurance> XML1
Store the XML string 2 in a variable  
2 store <insurance><age>45</age><income>20000</income><zipcode>10001</zipcode><result>You are eligible for a subsidy.</result></insurance>
XML2
Compare both XML strings and store result in ComparisonResult variable
3 xmlCompare
${XML1}||${XML2}
ComparisonResult

Tips, Tricks, Gotchas & Best Practices:  

  • You can also call the two XML strings directly in the target field separated by || symbol to compare them, instead of storing them into variables.
  • The XML should be valid and encoded in "UTF-8" format.
  • As a best practice, it is always advisable to define the variable names without any spaces and if you want to differentiate the words, use underscores.

Feedback and Knowledge Base