Ask a Question

Groovy : XML Comparison: Dynamic XML Attributes are not ignored whie comparison.

SOLVED
vpachpute1
Frequent Contributor

Groovy : XML Comparison: Dynamic XML Attributes are not ignored whie comparison.

Hi

 

I have one Groovy utility to compare current response with external response kept in xml file.

 

But while comparison, I am facing issue if parameter contains space. e.g.

1. If parameter is present as , subscription id .Then it is not ignored

2. If parameter is present as, subscription-id. Then it is ignored while comparison. Working file.

 

My case:

Actually in my case, subscription id will be dynamic. So while comparison , I added it in ignore list. So that next time this will be ignored while comparison.

 

Attached my groovy Utility and sample external response file.

 

Regards

Vishal

 

17 REPLIES 17
vpachpute1
Frequent Contributor

Hi

 

Can anyone please suggest any solution on this . Any help on this will be really appreciated.

 

Actually I am doubtful about following part.

If you look at other ignore elements like transaction-id, refund-enlargement-date etc, there are parameters. And if you look at subscription id, in this case, id is attribute.

So basically need to ignore this id attribute.

 

def elelist = ["subscription id", "refund-enlargement-date", "transaction-id"]

for (i in 0..(elelist.size())-1)
{
        varelement = elelist[i].toString()

        p = xml1.'**'."$varelement"
        p.each{ it.value = "This element is intentionally ignored for xml comparison" }

        p1 = xml.'**'."$varelement"
        p1.each{ it.value = "This element is intentionally ignored for xml comparison" }
      

// I have added this to ignore the id attribute. but not worked out.
        p2 = xml.'**'."$varelement"
        p2.each{ it.attributes().value = "This element is intentionally ignored for xml comparison" }

}

 

Regards

Vishal

The attributes method returns a Map, with the Key being the attribute name, thus to reference it:

 

it.attributes().get('id')

 

EDIT: The following page has a lot of good information about using the XmlParser:

 

http://groovy-lang.org/processing-xml.html

 

vpachpute1
Frequent Contributor

Hi

 

Thanks very much for your reply.

 

Can you please let me know how should I ignore <subscription id> in my following code while comparison.

 

Code for ignoring parameters while comparison

 

def elelist = ["id", "refund-enlargement-date", "transaction-id"]

for (i in 0..(elelist.size())-1)
{
        varelement = elelist[i].toString()

        p = xml1.'**'."$varelement"
        p.each{ it.value = "This element is intentionally ignored for xml comparison" }

        p1 = xml.'**'."$varelement"
        p1.each{ it.value = "This element is intentionally ignored for xml comparison" }

}

 

Thanks for your support.

 

Regards

Vishal

 

 

vpachpute1
Frequent Contributor

Hi  

 

Can you please help me ignoring this subscription id attribute while comparison in my xml comparison utility. Basically instead of element, I have to ignore attribute values.

 

I have tried this . But doesn't work. can you please correct me if I am wrong anywhere.

 

def elelist = ["id", "refund-enlargement-date", "transaction-id"]

for (i in 0..(elelist.size())-1)
{
        varelement = elelist[i].toString()

        p = xml1.'**'."$varelement"
        p.each{ it.value = "This element is intentionally ignored for xml comparison" }

        p1 = xml.'**'."$varelement"
        p1.each{ it.value = "This element is intentionally ignored for xml comparison" }

}

 

 

 

Sorry I don't have the time to go though all of your code in enough detail to give you the answer you want.

 

All I can point out is that you have to treat elements and attributes differently, the best I can suggest is to review the link I gave above about manipulating XML.

nmrao
Community Hero

Based on the attachment, you seemed to ignore all the elements. what is left out there to compare?


Regards,
Rao.
vpachpute1
Frequent Contributor

Hi

 

Actually the response xml is edited one. There are other parameters also.

 

From my response

def elelist = ["subscription id", "purchase-date", "expiry-date"]

 

Actually I have to ignore id attribute from subscription element. As id is dynamic.

 

Can you please let me know how to ignore attributes while comparison. (Not elements)

 

Regards

Vishal

vpachpute1
Frequent Contributor

Hi

 

Can anyone please help me on this.

 

Regards

Vishal

Can you post more details of the actual data(response) and expected data(master response) and ignore list details?

The above replies did not help, at least for me to offer any help.


Regards,
Rao.
cancel
Showing results for 
Search instead for 
Did you mean: