Author |
Message
|
Bharat |
Posted: Fri Oct 24, 2003 7:31 am Post subject: XML transformation in Compute Node |
|
|
 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 |
|
 |
EddieA |
Posted: Fri Oct 24, 2003 8:08 am Post subject: |
|
|
 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 |
|
 |
Bharat |
Posted: Fri Oct 24, 2003 8:28 am Post subject: XML transformation in Compute Node |
|
|
 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 |
|
 |
Bharat |
Posted: Fri Oct 24, 2003 9:27 am Post subject: |
|
|
 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 |
|
 |
EddieA |
Posted: Fri Oct 24, 2003 2:41 pm Post subject: |
|
|
 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 |
|
 |
Bharat |
Posted: Sat Oct 25, 2003 7:08 am Post subject: |
|
|
 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 |
|
 |
Bharat |
Posted: Sun Oct 26, 2003 4:32 pm Post subject: |
|
|
 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 |
|
 |
Tibor |
Posted: Mon Oct 27, 2003 2:02 pm Post subject: |
|
|
 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 |
|
 |
Bharat |
Posted: Mon Oct 27, 2003 2:44 pm Post subject: |
|
|
 Acolyte
Joined: 14 May 2002 Posts: 61 Location: Reston, VA, USA
|
Tiber,
Yes, it worked. Thank you so much.
Regards,
Bharat |
|
Back to top |
|
 |
|