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 » XML Tags

Post new topic  Reply to topic
 XML Tags « View previous topic :: View next topic » 
Author Message
anshu
PostPosted: Thu Jul 13, 2006 1:27 pm    Post subject: XML Tags Reply with quote

Novice

Joined: 23 Jan 2006
Posts: 19

I am doing a MRM to XML Transformation. I have an cobol layout of length 1700 (340 * 5) bytes. This data has to be mapped into XML as 5 chunks of 340 bytes each. The XML looks like below.

Requirement:

<Tags>
<Tag>
<name>T1</name>
<Value> 340 bytes of data </Value>
</Tag>
</Tags>

If all 1700 bytes has data, there will be T1, T2, T3, T4 and T5 tag. If however, say bytes 341 to 680 is blank, then we will have just 4 - T1, T2, T3 and T4.

Problem:

My code works well if any of the chunks 2 to 5 are blank. However if the very first 340 byte chunk of data is blank, my code generates an unwanted tag. I am wondering what is that generates XML when other (2 to 5) chunks are missing but messes it up if the very first chunk is blank.

Problem manifestation:

<Tags>
<Tag/> -------> THIS IS UNWANTED.
<Tag>
<name>T1</name>
<Value> 340 bytes of data </Value>
</Tag>
<Tag>
<name>T2</name>
<Value> 340 bytes of data </Value>
</Tag>
<Tag>
<name>T3</name>
<Value> 340 bytes of data </Value>
</Tag>
<Tag>
<name>T4</name>
<Value> 340 bytes of data </Value>
</Tag>
</Tags>


My ESQL Code is as follows:

Y = 0;
I1 = 1;
K1 = 340;
J1 = 1700;

CREATE FIELD OutputRoot.XML.Message.Tags.Tag TYPE Name;
DECLARE ref1 REFERENCE TO OutputRoot.XML.Message.Tags[1];
DECLARE ref2 REFERENCE TO OutputRoot.XML.Message.Tags.Tag[1];



X : WHILE I1 < J1 DO

-- process the while loop in K1 (ie 340) byte chunk iterations till you reach the 1700 bytes.


SET DATA = SUBSTRING(InputRoot.MRM.DATA FROM I1 FOR K1);
IF DATA = ' ' THEN ---- if data is blank, go to the next 340 byte chunk
SET I1 = I1+K1;
ITERATE X;
ELSE ---- if data is not blank, form the XML.
IF I1 > 1 THEN
CREATE LASTCHILD OF ref1 TYPE Name NAME 'Tag';
MOVE ref2 NEXTSIBLING;
END IF;
END IF;

SET Y = Y + 1;
SET name = 'T' || CAST(Y AS CHAR); -- this will create the T1, T2 etc
SET value = DATA;
SET ref2 = ROW(name AS name,
value AS Value);
SET I1 = I1+K1;
END WHILE X;

I appreciate any help from you guys.

Anshu


Last edited by anshu on Fri Jul 14, 2006 6:32 am; edited 2 times in total
Back to top
View user's profile Send private message
anshu
PostPosted: Fri Jul 14, 2006 3:03 am    Post subject: Reply with quote

Novice

Joined: 23 Jan 2006
Posts: 19

madi, jeff can you please let me know what's going wrong here.
Back to top
View user's profile Send private message
kimbert
PostPosted: Fri Jul 14, 2006 3:35 am    Post subject: Reply with quote

Jedi Council

Joined: 29 Jul 2003
Posts: 5542
Location: Southampton

Why are you using ESQL and SUBSTRING to split up the 1700-byte structure into its sub-fields. Surely it would be simpler to use the MRM parser for this?
If you are using the CWF physical format, the MRM's null handling features can automatically set the value of a field to null if it consists entirely of padding characters.
The structure of the output XML is bizarre - but you probably can't do anything about that.
Back to top
View user's profile Send private message
fjb_saper
PostPosted: Fri Jul 14, 2006 5:03 am    Post subject: Reply with quote

Grand High Poobah

Joined: 18 Nov 2003
Posts: 20756
Location: LI,NY

anshu wrote:
madi, jeff can you please let me know what's going wrong here.

Walk your execution logic through a white board changing the values at each loop and it will become luminously clear.
_________________
MQ & Broker admin
Back to top
View user's profile Send private message Send e-mail
anshu
PostPosted: Fri Jul 14, 2006 5:43 am    Post subject: XML Problem. Not a looping problem. Reply with quote

Novice

Joined: 23 Jan 2006
Posts: 19

I don't think it's the problem with the looping. It's a problem with the XML. If you observe the IF part of the statement (statement ITERATE X) , the code iterates to the next chunk whenever a chunk is empty.

This works fine - when any of chunks 2, 3, 4 or 5 is empty. This unwanted tag crops up only when first 340 byte chunk is empty. Everything in my output is as it needs to be except the unwanted tag,

This is existing production code. I don't want to complicate by changing the design. Any help will be appreciated.
Back to top
View user's profile Send private message
elvis_gn
PostPosted: Fri Jul 14, 2006 5:50 am    Post subject: Reply with quote

Padawan

Joined: 08 Oct 2004
Posts: 1905
Location: Dubai

Hi anshu,

The error is as below

You are creating an element tag using this line right at the top
Code:
CREATE FIELD OutputRoot.XML.Message.Tags.Tag TYPE Name;


Then when u go to the else becoz the data is blank, you do this
Code:
CREATE LASTCHILD OF ref1 TYPE Name NAME 'Tag';


Hence you have an extra empty tag at the top....

I guess u will be now be able to figure out a solution.

Regards.
Back to top
View user's profile Send private message Send e-mail
anshu
PostPosted: Fri Jul 14, 2006 6:05 am    Post subject: Reply with quote

Novice

Joined: 23 Jan 2006
Posts: 19

elvis,

I am close to your line of thinking. However, the else part gets executed only when DATA is present - not when it's blank.

I am thinking....

anshu
Back to top
View user's profile Send private message
elvis_gn
PostPosted: Fri Jul 14, 2006 6:19 am    Post subject: Reply with quote

Padawan

Joined: 08 Oct 2004
Posts: 1905
Location: Dubai

anshu wrote:
elvis,

I am close to your line of thinking. However, the else part gets executed only when DATA is present - not when it's blank.

I am thinking....

anshu


Whatever, the vice versa is what i meant then(that was the unimportant part in the post, and u saw only that and are still thinking ).

When the data is blank, the first tag is not populated but already existing becoz u created it already....and now on the next loop, the data is present so ur creating the lastchild of tag, which is the second tag...

How did you manage to get this code into production...and use a debugger, this is the exact reason why its provided.

Regards.
Back to top
View user's profile Send private message Send e-mail
anshu
PostPosted: Fri Jul 14, 2006 6:26 am    Post subject: elvis, no worries Reply with quote

Novice

Joined: 23 Jan 2006
Posts: 19

When I said I was thinking, I was not thinking about your post instead I was thinking a fix logic.

I fixed it. Simple counter flag to ignore the else part ONLY when the first chunk is blank.

By the way, I was not the original coder of the program
Back to top
View user's profile Send private message
elvis_gn
PostPosted: Fri Jul 14, 2006 11:09 pm    Post subject: Re: elvis, no worries Reply with quote

Padawan

Joined: 08 Oct 2004
Posts: 1905
Location: Dubai

Hi anshu,
anshu wrote:
When I said I was thinking, I was not thinking about your post instead I was thinking a fix logic.

I fixed it. Simple counter flag to ignore the else part ONLY when the first chunk is blank.

By the way, I was not the original coder of the program

You have only made the code much more complex than it already was...now that ur the owner of the code and u have the chance to make a change, make it the right one.

Remove the Create field tag from the top and do a create field only after u know a tag has to be created...thats in the else condition...currently ur doing a check if its the first data that is blank...what if the second, third etc data are blank...i am not certain if your code will work in all situations.

Regards.
Back to top
View user's profile Send private message Send e-mail
shrek
PostPosted: Thu Jul 20, 2006 3:51 am    Post subject: Reply with quote

Acolyte

Joined: 19 Feb 2005
Posts: 61
Location: Gudivada,India

I agree with Elvis.

Also, If those 340bytes of message data repeats based on value in some other field, why don't you use "OCCURS DEPENDING ON" in your copybook. What I'm trying to say is "offsetting 340bytes in every loop is okay but there are better ways of controlling it using the copybook". Thanks.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » WebSphere Message Broker (ACE) Support » XML Tags
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.