Groovy : XML Comparison: Dynamic XML Attributes are not ignored whie comparison.
SOLVED- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
Solved! Go to Solution.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Radford
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
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Radford
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" }
}
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Regards,
Rao.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi
Can anyone please help me on this.
Regards
Vishal
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The above replies did not help, at least for me to offer any help.
Regards,
Rao.
