Author |
Message
|
pa1 |
Posted: Tue Mar 27, 2012 7:44 pm Post subject: How to take the values of xml tag having attributes |
|
|
Novice
Joined: 20 Oct 2011 Posts: 13
|
Hi All,
I am getting input in the below way.
<y>
<x name="city">hyderabad</x>
<x name="country">in</x>
<x name="postalcode">1919</x>
</y>
I am accessing by arrays
IF refAttrSet.x[1].(XMLNSC.Attribute)name = 'city' THEN
SET outRef.city = refAttrSet.x[1];
END IF;
Is there any way with out using array count. please help me... I am using MB7 verion
thanks in advance for ur help |
|
Back to top |
|
 |
fjb_saper |
Posted: Tue Mar 27, 2012 9:09 pm Post subject: Re: How to take the values of xml tag having attributes |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
pa1 wrote: |
Hi All,
I am getting input in the below way.
<y>
<x name="city">hyderabad</x>
<x name="country">in</x>
<x name="postalcode">1919</x>
</y>
I am accessing by arrays
IF refAttrSet.x[1].(XMLNSC.Attribute)name = 'city' THEN
SET outRef.city = refAttrSet.x[1];
END IF;
Is there any way with out using array count. please help me... I am using MB7 verion
thanks in advance for ur help |
Yes you can use references like (from memory)
Code: |
DECLARE attname CHARACTER '';
DECLARE myref REFERENCE TO y;
DECLARE attbref REFERENCE TO y;
MOVE myref FIRSTCHILD NAME 'x';
WHILE LASTMOVE(myref) DO
MOVE attbref TO myref;
MOVE attbref FIRSTCHILD TYPE (XMLNSC.Attribute) NAME 'name';
-- alternatively to this while attbref loop you could use an IF condition...
WHILE LASTMOVE(attbref) DO
SET attname = FIELDVALUE(attbref);
CASE attname
WHEN 'city'
SET outRef.city = FIELDVALUE(myref);
WHEN 'country'
-- your code....
ELSE
-- default case
END CASE;
MOVE attbref NEXT SIBLING REPEAT NAME TYPE;
END WHILE; -- attbref
MOVE myref NEXT SIBLING REPEAT NAME TYPE;
END WHILE; -- myref
|
_________________ MQ & Broker admin |
|
Back to top |
|
 |
mqsiuser |
Posted: Tue Mar 27, 2012 10:22 pm Post subject: Re: How to take the values of xml tag having attributes |
|
|
 Yatiri
Joined: 15 Apr 2008 Posts: 637 Location: Germany
|
fjb_saper: Your code is so nice, I enjoy(ed) reading it. Thanks! _________________ Just use REFERENCEs |
|
Back to top |
|
 |
kimbert |
Posted: Wed Mar 28, 2012 1:15 am Post subject: |
|
|
 Jedi Council
Joined: 29 Jul 2003 Posts: 5542 Location: Southampton
|
This question crops up now and again - I've seen it before. I think it's an excellent opportunity to use the ESQL SELECT function. I would try something like this ( not tested ):
Code: |
SET outRef.city = FIELDVALUE(
SELECT Attrs.x
FROM refAttrSet AS Attrs
WHERE Attrs.x.name='city'
); |
|
|
Back to top |
|
 |
pa1 |
Posted: Fri Mar 30, 2012 3:25 am Post subject: |
|
|
Novice
Joined: 20 Oct 2011 Posts: 13
|
I have tried the above way but Its not working. and I have tried like this also
its not working please help
SET outRef.city =
SELECT Attrs.x
FROM refAttrSet AS Attrs
WHERE Attrs.x.(XMLNSC.Attribute)name='city'; |
|
Back to top |
|
 |
kimbert |
Posted: Fri Mar 30, 2012 3:44 am Post subject: |
|
|
 Jedi Council
Joined: 29 Jul 2003 Posts: 5542 Location: Southampton
|
Quote: |
I have tried the above way but Its not working. |
'Not working' does not help me ( or anybody else ) to help you. Either
a) tell us what actually happened, or
b) take some steps to diagnose the problem yourself. I recommend a Trace node and a user trace. |
|
Back to top |
|
 |
mqsiuser |
Posted: Fri Mar 30, 2012 4:54 am Post subject: |
|
|
 Yatiri
Joined: 15 Apr 2008 Posts: 637 Location: Germany
|
try "SELECT ITEM" (or "outRef.city[]")
Probably you need "THE(SELECT ITEM ..." _________________ Just use REFERENCEs |
|
Back to top |
|
 |
kimbert |
Posted: Fri Mar 30, 2012 6:25 am Post subject: |
|
|
 Jedi Council
Joined: 29 Jul 2003 Posts: 5542 Location: Southampton
|
ITEM and THE could be useful. Not sure that changing 'city' to 'city[]' will help pa1 - I think he's expecting a single (scalar ) result. |
|
Back to top |
|
 |
|