Author |
Message
|
rsk33 |
Posted: Thu Sep 06, 2012 5:43 am Post subject: Finding repeated tag duplicate values |
|
|
Centurion
Joined: 21 Aug 2006 Posts: 141
|
Hi
I am trying to find out repeated tag duplicate values in a XML request message. I tried with the below code but not successful. Any help is highly appreciated.
DECLARE Ref REFERENCE TO InputRoot.XMLNSC.TEST[1]
WHILE LASTMOVE(inRef) = TRUE DO
IF(SELECT count(*) FROM InputRoot.XMLNSC.TEST.Id[] AS F where F = Ref.Id) > 1 THEN
-- IF CARDINALITY(SELECT F.* FROM InputRoot.XMLNSC.TEST.Id[] AS F where F = Ref.Id ) > 1 THEN
SET Environment.variables.Duplicate = Ref.Id ;
END IF;
MOVE inRef NEXTSIBLING REPEAT TYPE NAME;
END WHILE;
input message is
<?xml version="1.0" encoding="UTF-8"?>
<Test>
<Id>1</Id>
</Test>
<Test>
<Id>1</Id>
</Test>
<Test>
<Id>2</Id>
</Test>
Regards |
|
Back to top |
|
 |
mqjeff |
Posted: Thu Sep 06, 2012 5:50 am Post subject: Re: Finding repeated tag duplicate values |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
rsk33 wrote: |
I tried with the below code but not successful. |
What was the result?
Why was the result 'unsuccessful'? |
|
Back to top |
|
 |
rsk33 |
Posted: Thu Sep 06, 2012 5:55 am Post subject: |
|
|
Centurion
Joined: 21 Aug 2006 Posts: 141
|
i debug and checked that the if condition is failing and moving to next sibling and the Environment.variables.Duplicate = Ref.Id is never set. |
|
Back to top |
|
 |
rsk33 |
Posted: Thu Sep 06, 2012 6:03 am Post subject: |
|
|
Centurion
Joined: 21 Aug 2006 Posts: 141
|
Hi jeff,
Thanks for the response. Am i missing something or any alternate code that can work. |
|
Back to top |
|
 |
mqjeff |
Posted: Thu Sep 06, 2012 6:15 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
rsk33 wrote: |
Hi jeff,
Thanks for the response. Am i missing something or any alternate code that can work. |
Well, your second attempt at the select is not strictly correct.
Code: |
SELECT count(*) FROM InputRoot.XMLNSC.TEST.Id[] AS F where F = Ref.Id |
should be
Code: |
SELECT count(F.*) FROM InputRoot.XMLNSC.TEST.Id[] AS F where F = Ref.Id |
And, in general, when I'm having trouble getting a condition statement to work, I rewrite it so I can observe both sides of the condition before the evaluation of the condition. So I'd put the select statement into a separate line and store the result into a local variable. then check if the local variable is > 1. |
|
Back to top |
|
 |
Vitor |
Posted: Thu Sep 06, 2012 6:18 am Post subject: |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
rsk33 wrote: |
Am i missing something |
That your SELECT is wrong
rsk33 wrote: |
any alternate code that can work. |
Well a correctly coded SELECT that returns a result would be a help.
Am I correct is saying you're trying to detect if an Id tag has the same value rather than the existance of multiple Id tags? If so you'd be looking for something like:
Code: |
IF CARDINALITY(SELECT F.Id FROM InputRoot.XMLNSC.Test[] AS F WHERE FIELDVALUE(F.Id) = FIELDVALUE(Ref.Id)) > 1 |
This code is untried, untested, would require some modifications to your loop and is provided for illustrative purposes only.
Better solutions are undoubtably possible and someone may post one.
I'd also repeat the advice to use a user trace rather than the debugger. That's showing you the condition is failing; the user trace will show you why it's failing. _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
rsk33 |
Posted: Thu Sep 06, 2012 6:42 am Post subject: |
|
|
Centurion
Joined: 21 Aug 2006 Posts: 141
|
Hi Jeff/victor
I tested both changes but the suggested cardinality is working.
Thanks a lot and also for the wonderful forum experts.
Regards |
|
Back to top |
|
 |
|