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 transformation in Compute Node

Post new topic  Reply to topic
 XML transformation in Compute Node « View previous topic :: View next topic » 
Author Message
Bharat
PostPosted: Fri Oct 24, 2003 7:31 am    Post subject: XML transformation in Compute Node Reply with quote

Acolyte

Joined: 14 May 2002
Posts: 61
Location: Reston, VA, USA

Hi,

I need to transform XML files from one format to another format using Compute Node of MQSI 2.0.1

My input XML file format is mentioned below. The tags can further be arrayed in this format.

<?xml version='1.0'?>
<projectrequest>
<requestbody>
<request>

<method>
<name>FirstMethod</name>

<argument>
<type>FirstArgument</type>
<FirstTag>Sample1</FirstTag>
<SecondTag>Sample2</SecondTag>
</argument>

</method>

<method>
<name>SecondMethod</name>

<argument>
<type>SecondArgument</type>
<ThirdTag>Sample3</ThirdTag>
<FourthTag>Sample4</FourthTag>
</argument>

<argument>
<type>SecondArgument</type>
<FifthTag>Sample5</FifthTag>
<SixthTag>Sample6</SixthTag>
</argument>

</method>

</request>
</requestbody>
</projectrequest>

My output XML file should look like:

<?xml version='1.0'?>
<request xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="SecondMethod.xsd">

<secondMethod>

<firstArgument>
<FirstTag>Sample1</FirstTag>
<SecondTag>Sample2</SecondTag>
</firstArgument>

<secondArgument>
<ThirdTag>Sample3</ThirdTag>
<FourthTag>Sample4</FourthTag>
</secondArgument>

<thirdArgument>
<FifthTag>Sample5</FifthTag>
<SixthTag>Sample6</SixthTag>
</thirdArgument>

</secondMethod>

</request>

The output file contains a single method and all the arguments are put inside this method.

Could you please guide me how to code using ESQL in compute node, to generate this format? I would sincerely appreciate your help.

Thanks in advance,
Bharat
Back to top
View user's profile Send private message
EddieA
PostPosted: Fri Oct 24, 2003 8:08 am    Post subject: Reply with quote

Jedi

Joined: 28 Jun 2001
Posts: 2453
Location: Los Angeles

What have you tried.

What are the problems you have.

Cheers,
_________________
Eddie Atherton
IBM Certified Solution Developer - WebSphere Message Broker V6.1
IBM Certified Solution Developer - WebSphere Message Broker V7.0
Back to top
View user's profile Send private message
Bharat
PostPosted: Fri Oct 24, 2003 8:28 am    Post subject: XML transformation in Compute Node Reply with quote

Acolyte

Joined: 14 May 2002
Posts: 61
Location: Reston, VA, USA

Eddie,

First let me thank you for your quick response.

My existing compute node uses the following code to transform the same input XML file into a different format.

DECLARE I INTEGER;
SET I = 1;
WHILE I < CARDINALITY(InputRoot.*[]) DO
SET OutputRoot.*[I] = InputRoot.*[I];
SET I=I+1;
END WHILE;

-- Declare Method Counter
DECLARE MIndex INTEGER;
-- Declare Argument Counter
DECLARE AIndex INTEGER;
-- Declare Record Counter
DECLARE RIndex INTEGER;
-- Declare Field Counter
DECLARE FIndex INTEGER;
-- Declare Temp Workspace
DECLARE Temp CHARACTER;

Set MIndex = 1;

-- Generate XML Contract

WHILE MIndex <= CARDINALITY(InputRoot.XML.projectroot.projectrequest.requestbody.request.method[]) DO
Set Temp = InputRoot.XML.projectroot.projectrequest.requestbody.request.method[MIndex].name;
Set OutputRoot.XML.projectroot.request.method[MIndex].(XML.attr)name=Temp;
Set AIndex = 1;
IF (InputRoot.XML.projectroot.projectrequest.requestbody.request.method[MIndex].argument[AIndex] IS NOT NULL) THEN
WHILE AIndex <= CARDINALITY(InputRoot.XML.projectroot.projectrequest.requestbody.request.method[MIndex].argument[]) DO
Set Temp = InputRoot.XML.projectroot.projectrequest.requestbody.request.method[MIndex].argument[AIndex].type;
Set OutputRoot.XML.projectroot.request.method[MIndex].argument[AIndex].(XML.attr)type=Temp;
Set FIndex = 1;
IF (InputRoot.XML.projectroot.projectrequest.requestbody.request.method[MIndex].argument[AIndex].FirstTag IS NOT NULL) THEN
Set Temp = InputRoot.XML.projectroot.projectrequest.requestbody.request.method[MIndex].argument[AIndex].FirstTag;
Set OutputRoot.XML.projectroot.request.method[MIndex].argument[AIndex].field[FIndex]=Temp;
Set OutputRoot.XML.projectroot.request.method[MIndex].argument[AIndex].field[FIndex].(XML.attr)name='FirstTag';
Set OutputRoot.XML.projectroot.request.method[MIndex].argument[AIndex].field[FIndex].(XML.attr)type='java.lang.String';
Set FIndex = FIndex +1;
END IF;
Set AIndex = AIndex +1;
END WHILE;
END IF;
Set MIndex = MIndex +1;
END WHILE;


The output XML format generated with the above code is mentioned below.


<?xml version="1.0"?>
<request>
<header/>
<method name="FirstMethod">
<argument type="FirstArgument">
<field name="FirstTag" type="java.lang.String">Sample1</field>
</argument>
</method>
</request>


I tried to change the above code to get the required new format, but I am unable to get the following format

<?xml version='1.0'?>
<request xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="SecondMethod.xsd">
<secondMethod>
<firstArgument>
<FirstTag>Sample1</FirstTag>
<SecondTag>Sample2</SecondTag>
</firstArgument>
<secondArgument>
<ThirdTag>Sample3</ThirdTag>
<FourthTag>Sample4</FourthTag>
</secondArgument>
<thirdArgument>
<FifthTag>Sample5</FifthTag>
<SixthTag>Sample6</SixthTag>
</thirdArgument>
</secondMethod>
</request>


Do I need to trim off the (XML.attr) kind of stuff? Could you pleas provide a sample code that generates the above format?

Thank you so much. I appreciate your help.

Regards,
Bharat
Back to top
View user's profile Send private message
Bharat
PostPosted: Fri Oct 24, 2003 9:27 am    Post subject: Reply with quote

Acolyte

Joined: 14 May 2002
Posts: 61
Location: Reston, VA, USA

Eddie,

My existing compute node uses the following code to transform the same input XML file into a different format.
Code:

DECLARE I INTEGER;
SET I = 1;
WHILE I < CARDINALITY(InputRoot.*[]) DO
   SET OutputRoot.*[I] = InputRoot.*[I];
   SET I=I+1;
END WHILE;

-- Declare Method Counter
DECLARE MIndex INTEGER;
-- Declare Argument Counter
DECLARE AIndex INTEGER;
-- Declare Record Counter
DECLARE RIndex INTEGER;
-- Declare Field Counter
DECLARE FIndex INTEGER;
-- Declare Temp Workspace
DECLARE Temp CHARACTER;

Set MIndex = 1;

-- Generate XML Contract

WHILE MIndex <= CARDINALITY(InputRoot.XML.projectroot.projectrequest.requestbody.request.method[]) DO
    Set Temp = InputRoot.XML.projectroot.projectrequest.requestbody.request.method[MIndex].name;
    Set OutputRoot.XML.projectroot.request.method[MIndex].(XML.attr)name=Temp;
    Set AIndex = 1;
    IF (InputRoot.XML.projectroot.projectrequest.requestbody.request.method[MIndex].argument[AIndex] IS NOT NULL) THEN
        WHILE AIndex <= CARDINALITY(InputRoot.XML.projectroot.projectrequest.requestbody.request.method[MIndex].argument[]) DO
            Set Temp = InputRoot.XML.projectroot.projectrequest.requestbody.request.method[MIndex].argument[AIndex].type;
            Set OutputRoot.XML.projectroot.request.method[MIndex].argument[AIndex].(XML.attr)type=Temp;
            Set FIndex = 1;
            IF (InputRoot.XML.projectroot.projectrequest.requestbody.request.method[MIndex].argument[AIndex].FirstTag IS NOT NULL) THEN
                Set Temp = InputRoot.XML.projectroot.projectrequest.requestbody.request.method[MIndex].argument[AIndex].FirstTag;
                Set OutputRoot.XML.projectroot.request.method[MIndex].argument[AIndex].field[FIndex]=Temp;
                Set OutputRoot.XML.projectroot.request.method[MIndex].argument[AIndex].field[FIndex].(XML.attr)name='FirstTag';
                Set OutputRoot.XML.projectroot.request.method[MIndex].argument[AIndex].field[FIndex].(XML.attr)type='java.lang.String';
                Set FIndex = FIndex +1;
            END IF;
        Set AIndex = AIndex +1;
        END WHILE;
    END IF;
    Set MIndex = MIndex +1;
END WHILE;           

The above code transforms the following existing input file into an output XML format mentioned below.
Existing input XML file format is:
Code:

<?xml version='1.0'?>
<projectrequest>
   <requestbody>
      <request>
         <method>
            <name>FirstMethod</name>
            <argument>
               <type>FirstArgument</type>
               <FirstTag>Sample1</FirstTag>
               <SecondTag>Sample2</SecondTag>
            </argument>
         </method>

         <method>
            <name>SecondMethod</name>
            <argument>
               <type>SecondArgument</type>
               <ThirdTag>Sample3</ThirdTag>
               <FourthTag>Sample4</FourthTag>
            </argument>
            <argument>
               <type>SecondArgument</type>
               <FifthTag>Sample5</FifthTag>
               <SixthTag>Sample6</SixthTag>
            </argument>            
         </method>
      </request>
   </requestbody>
</projectrequest>

Existing output XML file format into which the above code transforms the file is:
Code:

<?xml version="1.0"?>
<request>
   <header/>
   <method name="FirstMethod">
      <argument type="FirstArgument">
         <field name="FirstTag" type="java.lang.String">Sample1</field>
      </argument>
   </method>
</request>   

I tried to change the above code to get the required new format mentioned below, but I am unable to get this format
Code:

<?xml version='1.0'?>
<request xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="SecondMethod.xsd">
   <secondMethod>
      <firstArgument>
         <FirstTag>Sample1</FirstTag>
         <SecondTag>Sample2</SecondTag>
      </firstArgument>
      <secondArgument>
         <ThirdTag>Sample3</ThirdTag>
         <FourthTag>Sample4</FourthTag>
      </secondArgument>
      <thirdArgument>
         <FifthTag>Sample5</FifthTag>
         <SixthTag>Sample6</SixthTag>
      </thirdArgument>            
   </secondMethod>
</request>

Do I need to trim off the (XML.attr) kind of stuff? I tried by playing around the code. But no luck in getting the required new format. Could you please provide a sample code that generates the above format?

Thank you so much. I appreciate your help.

Regards,
Bharat
Back to top
View user's profile Send private message
EddieA
PostPosted: Fri Oct 24, 2003 2:41 pm    Post subject: Reply with quote

Jedi

Joined: 28 Jun 2001
Posts: 2453
Location: Los Angeles

Just saying you cannot get the right format is not enough information.

Which parts of the XML can you get correct. Which parts can't you.

What does your code and output look like.

Cheers,
_________________
Eddie Atherton
IBM Certified Solution Developer - WebSphere Message Broker V6.1
IBM Certified Solution Developer - WebSphere Message Broker V7.0
Back to top
View user's profile Send private message
Bharat
PostPosted: Sat Oct 25, 2003 7:08 am    Post subject: Reply with quote

Acolyte

Joined: 14 May 2002
Posts: 61
Location: Reston, VA, USA

Eddie,

Looks like I'm going in right direction. I'm trying with following code.
Code:

DECLARE I INTEGER;
SET I = 1;
WHILE I < CARDINALITY(InputRoot.*[]) DO
   SET OutputRoot.*[I] = InputRoot.*[I];
   SET I=I+1;
END WHILE;

-- Declare Method Counter
DECLARE MIndex INTEGER;
-- Declare Argument Counter
DECLARE AIndex INTEGER;
-- Declare Temp Workspace
DECLARE Temp CHARACTER;

Set OutputRoot.XML.tmrroot.request.header='';

Set MIndex = 1;
WHILE MIndex <= CARDINALITY(InputRoot.XML.tmrroot.projrequest.requestbody.request.method[]) DO
    Set AIndex = 1;
    IF (InputRoot.XML.projrequest.requestbody.request.method[MIndex].argument[AIndex] IS NOT NULL) THEN
        WHILE AIndex <= CARDINALITY(InputRoot.XML.projrequest.requestbody.request.method[MIndex].argument[]) DO
            Set FIndex = 1;
            IF (InputRoot.XML.projrequest.requestbody.request.method[MIndex].argument[AIndex].FirstTag IS NOT NULL) THEN
                Set Temp = InputRoot.XML.projrequest.requestbody.request.method[MIndex].argument[AIndex].FirstTag;
                Set OutputRoot.XML.request.NewMethod.NewArgument1.FirstTag=Temp;
                Set FIndex = FIndex +1;
            END IF;
        Set AIndex = AIndex +1;
        END WHILE;
    END IF;
    Set MIndex = MIndex +1;
END WHILE;

My request input XML file is:
Code:

<?xml version='1.0'?>
<projrequest>
   <requestbody>
      <request>
         <method>
            <name>FirstMethod</name>
            <argument>
               <type>FirstArgument</type>
               <FirstTag>777</FirstTag>
               <SecondTag>Sample2</SecondTag>               
            </argument>
         </method>
         <method>
            <name>SecondMethod</name>
            <argument>
               <type>SecondArgument</type>
               <ThirdTag>999</ThirdTag>
               <FourthTag>Sample4</FourthTag>
            </argument>
            <argument>
               <type>SecondArgument</type>
               <FifthTag>Sample5</FifthTag>
               <SixthTag>Sample6</SixthTag>
            </argument>             
         </method>
      </request>
   </requestbody>
</projrequest>

Output XML file that I'm getting is:
Code:

<?xml version="1.0" ?>
<request>
   <header/>
   <NewMethod>
      <NewArgument1>
         <FirstTag>777</FirstTag>
      </NewArgument1>
      <NewArgument2>
         <ThirdTag>999</ThirdTag>
      </NewArgument2>      
   </NewMethod>
</request>

The bottomline is I need to map all the values of tags like <FirstTag>, <SecondTag> etc. as child elements of <NewMethod> and <NewArgument> tags which are not there in the request file. I'm just hardcoding the <NewMethod> and <NewArgument> tags in my code. In the input file, I'm plalnning to loop thru all the methods and arguments in the input file to get the values of the corresponding tags. Hope there won't be any problem.

What do I need to add the in my code to get the following attribute added to the request tag in my output file?
Code:

<request xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="NewMethod.xsd">

Thanks,
Bharat
Back to top
View user's profile Send private message
Bharat
PostPosted: Sun Oct 26, 2003 4:32 pm    Post subject: Reply with quote

Acolyte

Joined: 14 May 2002
Posts: 61
Location: Reston, VA, USA

All my issues are resolved, except onething. I'm unable to generate the following XML tag.
Quote:
<request xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="SampleMethod.xsd">

I'm using the following code to generate the above request tag.
Code:
Set OutputRoot.XML.tmrroot.request.(XML.attr)xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance';
Set OutputRoot.XML.tmrroot.request.(XML.attr)xsi:noNamespaceSchemaLocation='SampleMethod.xsd';

I'm getting the following error.
Quote:
Syntax error : expected '=' but found ':'.
The expected token was not found.
Correct the syntax of your expression and redeploy the message flow.

I tried using '\' as escape character as mentioned below. But it didn't work.
Code:
Set OutputRoot.XML.tmrroot.request.(XML.attr)xmlns\:xsi='http://www.w3.org/2001/XMLSchema-instance';
Set OutputRoot.XML.tmrroot.request.(XML.attr)xsi\:noNamespaceSchemaLocation='SampleMethod.xsd';

Is there anyway, to include the ':' in my output XML file's request attribute name? Please help me in this.

Also, right now I'm hardcoding all the output XML tags in my compute node. There is no problem with this. But is there anyway that I can specify the DTD of my output XML file to any node and map all the fields of my input file?

Thank you so much,
Bharat
Back to top
View user's profile Send private message
Tibor
PostPosted: Mon Oct 27, 2003 2:02 pm    Post subject: Reply with quote

Grand Master

Joined: 20 May 2001
Posts: 1033
Location: Hungary

Bharat,

Try using double qoutes to suppress verifying in ESQL code, e.g.:
Code:
SET OutputRoot.XML.tmrroot.request.(XML.attr)"xmlns:xsi" = 'http://www.w3.org/2001/XMLSchema-instance';


I don't check it - but hope this helps,

Tibor
Back to top
View user's profile Send private message
Bharat
PostPosted: Mon Oct 27, 2003 2:44 pm    Post subject: Reply with quote

Acolyte

Joined: 14 May 2002
Posts: 61
Location: Reston, VA, USA

Tiber,

Yes, it worked. Thank you so much.

Regards,
Bharat
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 transformation in Compute Node
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.