|
RSS Feed - WebSphere MQ Support
|
RSS Feed - Message Broker Support
|
 |
|
XML Atribute query |
« View previous topic :: View next topic » |
Author |
Message
|
RAJESHRAMAKRISHNAN |
Posted: Tue Sep 14, 2004 11:24 pm Post subject: XML Atribute query |
|
|
Voyager
Joined: 01 May 2004 Posts: 96
|
Is it possible to do the following
I have an XML <A1><B1>1</B1><B1>2</B1><B1>3</B1></A1>
I want an output like this <A1Details><B1 Attr1=1/><B1 Attr1=2/><B1 Attr1=3/></A1Details> . Can I do this in one select statement ? If so is it possible to do even for multiple attributes ? ie like <B1 Attr1=1 Attr2 = 2/> etc in single select statement?
I guess we have to loop for so many times that B1 repeats . |
|
Back to top |
|
 |
kirani |
Posted: Wed Sep 15, 2004 2:44 pm Post subject: |
|
|
Jedi Knight
Joined: 05 Sep 2001 Posts: 3779 Location: Torrance, CA, USA
|
Not sure if you can do this in single statement. But you can write some ESQL code to loop thru the tree and crate output tree. _________________ Kiran
IBM Cert. Solution Designer & System Administrator - WBIMB V5
IBM Cert. Solutions Expert - WMQI
IBM Cert. Specialist - WMQI, MQSeries
IBM Cert. Developer - MQSeries
|
|
Back to top |
|
 |
shanson |
Posted: Thu Sep 16, 2004 8:09 am Post subject: |
|
|
 Partisan
Joined: 17 Oct 2003 Posts: 344 Location: IBM Hursley
|
I think you can do this in a single line of ESQL. If you use the MRM to parse the message, create two XML physical formats. The first format takes default values for XML Name and XML Render, the second changes the XML Name for A1 to be A1Details, and uses an XML Render of XMLElementAttrVal with an associated Value of 'Attr1'. Your single line of ESQL simply changes the message format in the output properties folder. |
|
Back to top |
|
 |
mgk |
Posted: Fri Sep 17, 2004 1:48 am Post subject: |
|
|
 Padawan
Joined: 31 Jul 2003 Posts: 1642
|
Hi,
There is another way as well to do what you want in a single ESQL SELECT, at least for the examples you provide:
Code: |
--copy mqmd
SET OutputRoot.MQMD = InputRoot.MQMD;
--this provides your first example
SET OutputRoot.XML.Top.A1Details.B1[] = (SELECT I.* AS (XML.Attribute)Attr1 FROM InputRoot.XML.A1.B1[] AS I);
--this provides your second example
SET OutputRoot.XML.Top.A2Details.B1[] = (SELECT I.[1].* AS (XML.Attribute)Attr1, I.[2].* AS (XML.Attribute)Attr2, I.[3].* AS (XML.Attribute)Attr3 FROM InputRoot.XML.A1[] AS I ); |
With the ESQL above, the input message you gave (
Code: |
<A1><B1>1</B1><B1>2</B1><B1>3</B1></A1> |
) gives the following output:
Code: |
<Top>
<A1Details>
<B1 Attr1="1"/>
<B1 Attr1="2"/>
<B1 Attr1="3"/>
</A1Details>
<A2Details>
<B1 Attr1="1" Attr2="2" Attr3="3"/>
</A2Details>
</Top> |
Which matches both example you give.
BTW, Don't forget to look in the ESQL Reference Guide in the Help though, as there are very similar examples of this
type of SELECT there.
Cheers, _________________ MGK
The postings I make on this site are my own and don't necessarily represent IBM's positions, strategies or opinions. |
|
Back to top |
|
 |
RAJESHRAMAKRISHNAN |
Posted: Fri Sep 17, 2004 5:05 am Post subject: |
|
|
Voyager
Joined: 01 May 2004 Posts: 96
|
Thanks very much. Will try this. |
|
Back to top |
|
 |
|
|
 |
|
Page 1 of 1 |
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|
|
|