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 » CREATE NEXTSIBLING OF - I must be doing something wrong

Post new topic  Reply to topic
 CREATE NEXTSIBLING OF - I must be doing something wrong « View previous topic :: View next topic » 
Author Message
Vifferrider
PostPosted: Mon Mar 02, 2015 5:23 am    Post subject: CREATE NEXTSIBLING OF - I must be doing something wrong Reply with quote

Newbie

Joined: 02 Mar 2015
Posts: 3

Hi

I am parsing an incoming XML that has a structure of

<OrderItems>
<OrderItem>
<OrderLineItemId>0</OrderLineItemId>
<ProductName>Product 1 Cert</ProductName>
</OrderItem>
<OrderItem>
<OrderLineItemId>1</OrderLineItemId>
<ProductName>Special Letter 2</ProductName>
</OrderItem>
<OrderItem>
<OrderLineItemId>2</OrderLineItemId>
<ProductName>Info Pack 3</ProductName>
</OrderItem>
</OrderItems>

and am using (an abridge version of the code)

Code:
    DECLARE rItems REFERENCE TO InputRoot.XMLNSC.*:Order.*:OrderItems.*;
    DECLARE rLines REFERENCE TO OutputRoot;
    DECLARE LineCount INT;
    SET LineCount=0;
    CREATE FIELD OutputRoot.XMLNSC.order.lines AS rLines;
       
    WHILE LASTMOVE(rItems) DO
        SET LineCount = LineCount + 1;
        SET rLines.line.lineno = LineCount;
           SET rLines.line.ourdescription  = rItems.ProductName;
           SET rLines.line.yourstockcode  = '';
           SET rLines.line.yourdescription  = '';
           SET rLines.line.uom  = '';
            CREATE NEXTSIBLING OF rLines AS rLines REPEAT;
           MOVE rItems NEXTSIBLING REPEAT TYPE N   AME;
   END WHILE;


I am getting

<lines>
<line>
<lineno>1</lineno>
<ourdescription>Product 1 Cert</ourdescription>
<yourstockcode></yourstockcode>
<yourdescription></yourdescription>
<uom></uom>
</line>
</lines>
<lines>
<line>
<lineno>2</lineno>
<ourdescription>Special Letter 2</ourdescription>
<yourstockcode></yourstockcode>
<yourdescription></yourdescription>
<uom></uom>
</line>
</lines>
<lines>
<line>
<lineno>3</lineno>
<ourdescription>Info Pack 3</ourdescription>
<yourstockcode></yourstockcode>
<yourdescription></yourdescription>
<uom></uom>
</line>
</lines>
<lines/>

and expect it to be along the structure of

<lines>
<line>
Blah
Blah
</line>
<line>
Blah
Blah
</line>
<line>
Blah
Blah
</line>
</lines>

Please can you advise what I am doing wrong >

thanks
[/code]
Back to top
View user's profile Send private message
Vitor
PostPosted: Mon Mar 02, 2015 6:42 am    Post subject: Re: CREATE NEXTSIBLING OF - I must be doing something wrong Reply with quote

Grand High Poobah

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

Vifferrider wrote:
Please can you advise what I am doing wrong >


Your CREATE should be at the start not the end.
_________________
Honesty is the best policy.
Insanity is the best defence.
Back to top
View user's profile Send private message
joebuckeye
PostPosted: Mon Mar 02, 2015 7:39 am    Post subject: Reply with quote

Partisan

Joined: 24 Aug 2007
Posts: 365
Location: Columbus, OH

The line
Quote:
CREATE NEXTSIBLING OF rLines AS rLines REPEAT;

is creating a new entry of <lines> which does not appear to be what you want.
Back to top
View user's profile Send private message
Vifferrider
PostPosted: Mon Mar 02, 2015 9:47 am    Post subject: Re: CREATE NEXTSIBLING OF - I must be doing something wrong Reply with quote

Newbie

Joined: 02 Mar 2015
Posts: 3

Vitor wrote:
Vifferrider wrote:
Please can you advise what I am doing wrong >


Your CREATE should be at the start not the end.


I have done this but still not right

Now I get

<lines>
<line>
Blah
Blah
</line>

</lines>
<lines>
<line>
Blah
Blah
</line>
</lines>

<lines>
<line>
Blah
Blah
</line>
</lines>
Back to top
View user's profile Send private message
joebuckeye
PostPosted: Mon Mar 02, 2015 9:56 am    Post subject: Reply with quote

Partisan

Joined: 24 Aug 2007
Posts: 365
Location: Columbus, OH

Your code is creating a new <lines> element each time through your loop.

The CREATE statement inside your loop should not be there.
Back to top
View user's profile Send private message
Vifferrider
PostPosted: Mon Mar 02, 2015 2:06 pm    Post subject: Reply with quote

Newbie

Joined: 02 Mar 2015
Posts: 3

Sussed it, with thanks to the pointers given

Code:
        WHILE LASTMOVE(rItems) DO
           SET LineCount = LineCount + 1;
           SET rLines.line[LineCount].lineno = LineCount;
           SET rLines.line[LineCount].ourdescription  = rItems.ProductName;
           SET rLines.line[LineCount].yourstockcode  = '';
           SET rLines.line[LineCount].yourdescription  = '';
           SET rLines.line[LineCount].unitprice  = rItems.ItemTotal;
                        SET rLines.line[LineCount].uom  = '';
           MOVE rItems NEXTSIBLING REPEAT TYPE NAME;
   END WHILE;


Thanks all
Back to top
View user's profile Send private message
adubya
PostPosted: Tue Mar 03, 2015 2:20 am    Post subject: Reply with quote

Partisan

Joined: 25 Aug 2011
Posts: 377
Location: GU12, UK

Vifferrider wrote:
Sussed it, with thanks to the pointers given

Code:
        WHILE LASTMOVE(rItems) DO
           SET LineCount = LineCount + 1;
           SET rLines.line[LineCount].lineno = LineCount;
           SET rLines.line[LineCount].ourdescription  = rItems.ProductName;
           SET rLines.line[LineCount].yourstockcode  = '';
           SET rLines.line[LineCount].yourdescription  = '';
           SET rLines.line[LineCount].unitprice  = rItems.ItemTotal;
                        SET rLines.line[LineCount].uom  = '';
           MOVE rItems NEXTSIBLING REPEAT TYPE NAME;
   END WHILE;



Thanks all



Using arrays is an inefficient way of traversing message structures and should be avoided where possible.

How about:-

Code:

    DECLARE rItems REFERENCE TO InputRoot.XMLNSC.*:Order.*:OrderItems.*;
    DECLARE rLines, rLine REFERENCE TO OutputRoot;
    DECLARE LineCount INT;
    SET LineCount=0;
    CREATE FIELD OutputRoot.XMLNSC.order.lines AS rLines;
       
    WHILE LASTMOVE(rItems) DO
      CREATE LASTCHILD OF rLines AS rLine NAME 'line'
        SET LineCount = LineCount + 1;
        SET rLine.lineno = LineCount;
        SET rLine.ourdescription  = rItems.ProductName;
        SET rLine.yourstockcode  = '';
        SET rLine.yourdescription  = '';
        SET rLine.uom  = '';
        MOVE rItems NEXTSIBLING REPEAT TYPE NAME;
   END WHILE;


(typed in blind, not tested )
Back to top
View user's profile Send private message Send e-mail
joebuckeye
PostPosted: Tue Mar 03, 2015 7:06 am    Post subject: Reply with quote

Partisan

Joined: 24 Aug 2007
Posts: 365
Location: Columbus, OH

Yes, time for refactoring now to make it better.

I would ditch the WHILE and use FOR. The FOR statement simplifies the setup for looping through items.

Code:

DECLARE rLines, rLine REFERENCE TO OutputRoot;
DECLARE LineCount INT;
SET LineCount=0;
CREATE FIELD OutputRoot.XMLNSC.order.lines AS rLines;
     
FOR itemsRef AS InputRoot.XMLNSC.*:Order.*:OrderItems[] DO
        CREATE LASTCHILD OF rLines AS rLine NAME 'line'
        SET LineCount = LineCount + 1;
        SET rLine.lineno = LineCount;
        SET rLine.ourdescription  = itemsRef .ProductName;
        SET rLine.yourstockcode  = '';
        SET rLine.yourdescription  = '';
        SET rLine.uom  = '';
   END FOR;


Again, this is blind typed in, not tested.
Back to top
View user's profile Send private message
adubya
PostPosted: Tue Mar 03, 2015 8:00 am    Post subject: Reply with quote

Partisan

Joined: 25 Aug 2011
Posts: 377
Location: GU12, UK

Good call!
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » WebSphere Message Broker (ACE) Support » CREATE NEXTSIBLING OF - I must be doing something wrong
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.