ASG
IBM
Zystems
Cressida
Icon
Netflexity
 
  MQSeries.net
Search  Search       Tech Exchange      Education      Certifications      Library      Info Center      SupportPacs      LinkedIn  Search  Search                                                                   FAQ  FAQ   Usergroups  Usergroups
 
Register  ::  Log in Log in to check your private messages
 
RSS Feed - WebSphere MQ Support RSS Feed - Message Broker Support

MQSeries.net Forum Index » WebSphere Message Broker (ACE) Support » move multiple fields

Post new topic  Reply to topic
 move multiple fields « View previous topic :: View next topic » 
Author Message
agrawalamit166
PostPosted: Mon Dec 10, 2012 7:47 am    Post subject: move multiple fields Reply with quote

Voyager

Joined: 17 Aug 2009
Posts: 78
Location: NY, US

Hi
I have
Quote:

Input message:
<Root>
<core>
<x>a</x>
<y>b</y>
<z>c</z>
</core>
<optional>
<x>d</x>
<y>e</y>
<z>f</z>
<x>g</x>
<y>h</y>
</optional>
</Root>

I need to convert this message into
Quote:

Output Message:
<Root>
<core>
<x>a</x>
<y>b</y>
<z>c</z>
<x>d</x>
<y>e</y>
<z>f</z>
<x>g</x>
<y>h</y>
</core>
</Root>

The problem, I am facing, is: how to add optional tree at the end of "Core". Optional does not contain same type of records (x,y,z etc...)
Back to top
View user's profile Send private message Yahoo Messenger
mqjeff
PostPosted: Mon Dec 10, 2012 7:51 am    Post subject: Reply with quote

Grand Master

Joined: 25 Jun 2008
Posts: 17447

In ESQL, you can add these elements using the SET statement.
Back to top
View user's profile Send private message
agrawalamit166
PostPosted: Mon Dec 10, 2012 7:57 am    Post subject: Reply with quote

Voyager

Joined: 17 Aug 2009
Posts: 78
Location: NY, US

I know that but the problem is: if i use set , then it will override the previous element.
If I use CREATE LASTCHILD OF OutputRoot.XMLNSC.Root.Core... then I need to loop it for number of element inside <Optional>
Back to top
View user's profile Send private message Yahoo Messenger
Vitor
PostPosted: Mon Dec 10, 2012 8:07 am    Post subject: Reply with quote

Grand High Poobah

Joined: 11 Nov 2005
Posts: 26093
Location: Texas, USA

agrawalamit166 wrote:
I know that but the problem is: if i use set , then it will override the previous element.


Not if you use 1 SET statement to build the whole of OutputRoot.XMLNSC.Root.Core, including the bits which exist in the InputRoot already.
_________________
Honesty is the best policy.
Insanity is the best defence.
Back to top
View user's profile Send private message
mqjeff
PostPosted: Mon Dec 10, 2012 8:08 am    Post subject: Reply with quote

Grand Master

Joined: 25 Jun 2008
Posts: 17447

Or you can use a SELECT statement.

Or you can not use ESQL and use other methods in other transformation interfaces.
Back to top
View user's profile Send private message
Vitor
PostPosted: Mon Dec 10, 2012 8:15 am    Post subject: Reply with quote

Grand High Poobah

Joined: 11 Nov 2005
Posts: 26093
Location: Texas, USA

mqjeff wrote:
Or you can use a SELECT statement.


In truth, I'd probably do it with a SELECT statement if I actually had to do it.
_________________
Honesty is the best policy.
Insanity is the best defence.
Back to top
View user's profile Send private message
agrawalamit166
PostPosted: Mon Dec 10, 2012 8:42 am    Post subject: Reply with quote

Voyager

Joined: 17 Aug 2009
Posts: 78
Location: NY, US

The problem with SELECT is: how to add two inputs (<core><element> && <optional><element>)

The Actual tree is like:
Quote:

<Root>
<info>
<core>
<element>
<x><a>Complex tree node</a></x>
<y>Simple tree node</y>
<z><c><a>Complex tree node</a></c></z>
</element>
</core>
<optional>
<element> <x>d</x><y>e</y><z>f</z><x>g</x><y>h</y><z>d</z><x>c</x><y>b</y><z>a</z>
</element>
</optional>
</info>

<info><core><element>
<x>a</x>
<y>b</y>
<z>c</z>
</element>
</core>
<optional>
<element> <x>d</x><y>e</y><z>f</z><x>g</x><y>h</y><z>d</z><x>c</x><y>b</y><z>a</z>
</element>
</optional>
</info>
</Root>


I am using following code right now in ESQL:


Code:

I create the Reference for <info> tag and

WHILE(LASTMOVE(infoRef) AND i < 100) DO
   SET outputRef.info[count].core = infoRef.core;  ---- i got the outputRef.info[count].core.element with x..y..z.. tags
   SET outputRef.info[count].core.element= infoRef.optional.element.*; --- I know this statement is wrong, but want to know how can I put this
   SET count = count + 1;
   MOVE infoRef NEXTSIBLING REPEAT TYPE NAME;
   SET i = i + 1;
END WHILE;
Back to top
View user's profile Send private message Yahoo Messenger
mqjeff
PostPosted: Mon Dec 10, 2012 8:48 am    Post subject: Reply with quote

Grand Master

Joined: 25 Jun 2008
Posts: 17447

You tell the select statement to select two things from two parts of the input message.
Back to top
View user's profile Send private message
agrawalamit166
PostPosted: Mon Dec 10, 2012 9:38 am    Post subject: Reply with quote

Voyager

Joined: 17 Aug 2009
Posts: 78
Location: NY, US

I use SELECT but it still overriding the core element value:

Code:

SET outputRef.info[] = (SELECT I.core.element, 
          I.optional.element  FROM InputRef.info[] AS I );
Back to top
View user's profile Send private message Yahoo Messenger
mqsiuser
PostPosted: Tue Dec 11, 2012 12:57 am    Post subject: Reply with quote

Yatiri

Joined: 15 Apr 2008
Posts: 637
Location: Germany

agrawalamit166 wrote:
I know that but the problem is: if i use set , then it will override the previous element.

Yes, that is how SET works. And using SET-Statements (when possible) (and with references ) is the usual way you code in ESQL.

agrawalamit166 wrote:
If I use CREATE LASTCHILD OF OutputRoot.XMLNSC.Root.Core... then I need to loop it for number of element inside <Optional>

Yes, I would do it like this.

ESQL-SELECT will (either) just do the same thing (internally) (or it does something else: Happy guessing... and if you are lucky it ends up with what you would (just) code yourself. (That's a bit negative... what ESQL-SELECT does is documented properly ofc. somewhere)).

Probably ESQL-SELECT may be faster (since it uses native-c)... so I'd consider using SELECT if I'd have problems with ESQL-Reference-Tree-walking's performance (which is unlikely to happen)).

So I highly recommend that you just write an ESQL-Reference-Loop (with CREATE (LASTCHILD) statements)

You may think... "Ah, I spare time, when I write the SELECT"... but I do not think that this happens: You may be quicker coding a SELECT initially... but you might not be able to adjust it freely and it may not do what you want it to do (you actually confirmed that in your last post) and then you might not bring it to do what you want it to do.
_________________
Just use REFERENCEs
Back to top
View user's profile Send private message
agrawalamit166
PostPosted: Tue Dec 11, 2012 7:38 am    Post subject: Reply with quote

Voyager

Joined: 17 Aug 2009
Posts: 78
Location: NY, US

Thanks MqsiUser, for you comments...

I am using Create Last child option. and this is fine for simple tree node.

for example: <x>a</x>
But I am getting issue with complex tree:
Example: <attGroup id="1"> <attr name="Name">AAA</attr><attr name="Address">BBBB</attr></attGroup>

I write this code:
Code:

DECLARE optionalAttrRef REFERENCE TO gtinInfoRef.optional.element.*[1];
WHILE(LASTMOVE(optionalAttrRef) AND i < 100) DO
 CREATE LASTCHILD OF outputRef.core[count].element NAME FIELDNAME(optionalAttrRef) VALUE optionalAttrRef;
 SET outputRef.core[count].element.*[<].(XMLNSC.Attribute)id = optionalAttrRef.(XMLNSC.Attribute)id;
 SET outputRef.core[count].element.*[<].*[] = optionalAttrRef.*[];
END WHILE;

above mentioned code just adds the "ID" attribute but Sub tree are still not associated with AttrGroup node.

Thanks,
Amit
Back to top
View user's profile Send private message Yahoo Messenger
agrawalamit166
PostPosted: Tue Dec 11, 2012 7:54 am    Post subject: Reply with quote

Voyager

Joined: 17 Aug 2009
Posts: 78
Location: NY, US

I got the Solution for this:

Code:

DECLARE optionalAttrRef REFERENCE TO gtinInfoRef.optional.element.*[1];
WHILE(LASTMOVE(optionalAttrRef) AND i < 100) DO
 CREATE LASTCHILD OF outputRef.core[count].element NAME FIELDNAME(optionalAttrRef) VALUE optionalAttrRef;
 SET outputRef.core[count].element.*[<].(XMLNSC.Attribute)id = optionalAttrRef.(XMLNSC.Attribute)id;
 SET outputRef.core[count].element.*[<] = optionalAttrRef;
END WHILE;


Now This is working fine for me. Thanks a lot for your support....
Back to top
View user's profile Send private message Yahoo Messenger
mqsiuser
PostPosted: Thu Dec 13, 2012 5:21 am    Post subject: Reply with quote

Yatiri

Joined: 15 Apr 2008
Posts: 637
Location: Germany

Quote:
DECLARE optionalAttrRef REFERENCE TO gtinInfoRef.optional.element.*[1];
WHILE(LASTMOVE(optionalAttrRef) AND i < 100) DO
CREATE LASTCHILD OF outputRef.core[count].element NAME FIELDNAME(optionalAttrRef) VALUE optionalAttrRef;
SET outputRef.core[count].element.*[<].(XMLNSC.Attribute)id = optionalAttrRef.(XMLNSC.Attribute)id;
SET outputRef.core[count].element.*[<] = optionalAttrRef;
END WHILE;


Your ESQL looks as if you could optimize it a bit, though Programmer time is expensive (we are so expensive ) so you just leave it as it is (as long as you don't get into performance issues).

I think the bold parts might / can be optimized:

1. Just use LASTMOVE (it is unlikely that you need integer-variables, like "i" or "count")
2. Accessing elements with long paths (on one line) can also likely be / get replaced with a REFERENCE
3. Accesssing elements with [count] can also usually be avoided.

AND usually you should have a MOVE optionalAttrRef NEXT ... before "END WHILE"

Try to walk along the leaves (of the tree)
_________________
Just use REFERENCEs
Back to top
View user's profile Send private message
mqjeff
PostPosted: Thu Dec 13, 2012 5:34 am    Post subject: Reply with quote

Grand Master

Joined: 25 Jun 2008
Posts: 17447

agrawalamit166 wrote:
I use SELECT but it still overriding the core element value:

Code:

SET outputRef.info[] = (SELECT I.core.element, 
          I.optional.element  FROM InputRef.info[] AS I );


I would have done
Code:
 Set OutputRef.info[] = SELECT I.element, J.element from InputRef.info.core.[] as I, InputRef.optional.[] as J


I do not say this will work any better, just that it's closer to what I suggested.
Back to top
View user's profile Send private message
agrawalamit166
PostPosted: Thu Dec 13, 2012 1:50 pm    Post subject: Reply with quote

Voyager

Joined: 17 Aug 2009
Posts: 78
Location: NY, US

Code:

Set OutputRef.info[] = SELECT I.element, J.element from InputRef.info.core.[] as I, InputRef.optional.[] as J

I will look into it and update you whether it works for me or not.

Quote:

1. Just use LASTMOVE (it is unlikely that you need integer-variables, like "i" or "count")
2. Accessing elements with long paths (on one line) can also likely be / get replaced with a REFERENCE
3. Accesssing elements with [count] can also usually be avoided.

AND usually you should have a MOVE optionalAttrRef NEXT ... before "END WHILE"

1. We have a requirement to do it till 100 element.
2. I have removed
Code:

SET outputRef.core[count].element.*[<].(XMLNSC.Attribute)id = optionalAttrRef.(XMLNSC.Attribute)id;

Because next line does this task as well
Code:

SET outputRef.core[count].element.*[<] = optionalAttrRef;

3. I will try to avoid count...

obviously i am using MOVE optionalAttrRef NEXTSIBLING; and increamenting "i" and count.

Thanks,
Amit
Back to top
View user's profile Send private message Yahoo Messenger
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » WebSphere Message Broker (ACE) Support » move multiple fields
Jump to:  



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
Protected by Anti-Spam ACP
 
 


Theme by Dustin Baccetti
Powered by phpBB © 2001, 2002 phpBB Group

Copyright © MQSeries.net. All rights reserved.