Ask a Question

How to compare a node value in one xml to similar nodes in another xml

SOLVED
AA26
New Contributor

How to compare a node value in one xml to similar nodes in another xml

I have 2 XMLs and need to compare the node values.

example:

XML1 has 4 firstname and 4 last name node and same with XML2 but both are not in same order.

I need to make sure that all the 4 names in XML1 match with all 4 in XML2 ( if not first element then looping through remining)

I have tried getNodeValues and am getting the values but not sure on comaparing them. 

Can someone please help me as am new to groovy and this is very confusing for me

4 REPLIES 4
nmrao
Community Hero

Please add sample xmls and specify which data to be compared. That would help to understand easily. Need not be exact data, but same structure.


Regards,
Rao.
AA26
New Contributor

xml1 and xml 2 same format

<body>

<service>

<fill>

<response>

<DR>

   <Inc> 

    <desc>abc</desc>

    <date>111 </date>

  <inc>

 <Inc> 

    <desc>def</desc>

    <date>222</date>

  <inc>

<DR>

<response>

<fill>

<service>

<body>

 

now I need to take the values for xml1 (desc and date combination from inc ) and compare it to all same fields in xml 2. abc-111 combination on xml1 is the first inc of the xml1 but it need not be the first in the xml2. 

similarly I can have multiple Inc in one xml and need to compare all of them to match on  the second and provide pass whenever it matches. if it matches on the first -first combination, then I need to start searching for second Inc on xml 2. if this is not in second place on xml2, I need to search all the remainiung Inc

The desc can be repaeating for multiple Inc

 

 

nmrao
Community Hero

Create a sorted list for each <inc> by <desc> element; and each element in the should be a map which contains <desc>, <date> and their values as key, value pairs. Do the same for xml2. Then compare both the lists.
Should come something like:
xml1 = [ [desc: 'abc', date: '111'], [desc: 'def', date:'222']]
xml2 should also be same.


Regards,
Rao.
Olga_T
SmartBear Alumni (Retired)

Thank you for the suggestion, @nmrao.

 

@AA26, is this what you were looking for?


Olga Terentieva
SmartBear Assistant Community Manager

cancel
Showing results for 
Search instead for 
Did you mean: