Author |
Message
|
rajaram |
Posted: Tue Mar 23, 2004 6:32 am Post subject: Problem searching for a field value in XML message. |
|
|
Acolyte
Joined: 02 Jan 2004 Posts: 53
|
Hi,
I have a problem searching an XML message.
I have a field(element) called <at id='222'> which occurs multiple times in another field(element) called <class id> which also occurs many times.
I did this:
DECLARE T REFERENCE TO "InputBody"."XX"."class"[];
SET "OutputRoot"."MRM"."AAA" = THE(SELECT ITEM R."value" FROM T."at"[] AS R WHERE R."id" = '123');
But this doesnt seem to work as the select statement searches only the first <class id > element
The aboc statement will not wrok for the following kind of message
eg:
<class id=1>
<at id="222"></at>
</class>
<class id = 2>
<at id ="123"></at>
</class>
If i want to search for an <at id> in the entire XML message. Is there any other way i can try?
I could use while loop but there are many mappings...which makes my code highly inefficient.
Please Help |
|
Back to top |
|
 |
fjcarretero |
Posted: Tue Mar 23, 2004 6:42 am Post subject: |
|
|
Voyager
Joined: 13 Oct 2003 Posts: 88
|
You could try nesting the select statements
Something like:
Code: |
SET "OutputRoot"."MRM"."AAA" = THE(SELECT (SELECT ITEM R."value" FROM T."at"[] AS R WHERE R."id" = '123') FROM "InputBody"."XX"."class"[] AS T);
|
I haven't tested it
Hope this helps
Felipe |
|
Back to top |
|
 |
jefflowrey |
Posted: Tue Mar 23, 2004 6:51 am Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
If your Input message is in the XML domain (rather than XML modelled in MRM), then you'll need to indicate that "id" is an XML.Attribute, and not just a plain XML.Element. _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
Missam |
Posted: Tue Mar 23, 2004 7:39 am Post subject: |
|
|
Chevalier
Joined: 16 Oct 2003 Posts: 424
|
what jeff is referring to is right.you need to perform a check on the Attribue rather that the content of at[].try this one
Code: |
SET "OutputRoot"."XML"."AAA" = THE(SELECT R."value" FROM "InputBody"."Message"."class"[] as T,T."at"[] AS R WHERE R.(XML.Attribute)"id" = '123'); |
|
|
Back to top |
|
 |
rajaram |
Posted: Tue Mar 23, 2004 10:11 am Post subject: BOTH THE CODES ARE NOT WORKING |
|
|
Acolyte
Joined: 02 Jan 2004 Posts: 53
|
SET "OutputRoot"."MRM"."AAA" = THE(SELECT (SELECT ITEM R."value" FROM T."at"[] AS R WHERE R."id" = '123') FROM "InputBody"."XX"."class"[] AS T);
THIS STATEMENT WOULD SELECT content of R."value" first and try to search it in "inputbody"."xx"."class",which obviously is not present.
------------------------------------------
SET "OutputRoot"."XML"."AAA" = THE(SELECT R."value" FROM "InputBody"."Message"."class"[] as T,T."at"[] AS R WHERE R.(XML.Attribute)"id" = '123');
this would not solve my problem as the select statement still searches only the first <class> |
|
Back to top |
|
 |
Missam |
Posted: Tue Mar 23, 2004 11:09 am Post subject: |
|
|
Chevalier
Joined: 16 Oct 2003 Posts: 424
|
Quote: |
this would not solve my problem as the select statement still searches only the first <class> |
I don't think the search ends with only the first <class> in your message.Did you tried it...?
the problem here is not about using
Code: |
SET "OutputRoot"."MRM"."AAA" = THE(SELECT (SELECT ITEM R."value" FROM T."at"[] AS R WHERE R."id" = '123') FROM "InputBody"."XX"."class"[] AS T); |
or
Code: |
SET "OutputRoot"."XML"."AAA" = THE(SELECT R."value" FROM "InputBody"."Message"."class"[] as T,T."at"[] AS R WHERE R.(XML.Attribute)"id" = '123'); |
The Point here is you need to look into Attribute of the field rather that conent of the field to satisy your search requirement. |
|
Back to top |
|
 |
rajaram |
Posted: Tue Mar 23, 2004 10:08 pm Post subject: Let me put my problem in simple words |
|
|
Acolyte
Joined: 02 Jan 2004 Posts: 53
|
XML message:
<top level>
<class id=1>
<at id="222">
<text id= "456">Hello World</text>
</at>
</class>
<class id = 2>
<at id ="123">
<text id= "789">Hi </text>
</at>
</class>
<class id=3>
.
.
.
.
.
</top level>
I need to search for the <text> and not the attribute of <text>...based on the value of attribute 'id' of 'at'..ie
if at.(XML.Attribute)id = '123' then
set output.mrm.aaa = at.text
end if
Now the problem is i need to search for this in every class without using a while loop.
How do i do that?? |
|
Back to top |
|
 |
|