Author |
Message
|
Gemz |
Posted: Tue Oct 14, 2008 7:44 am Post subject: To form XML from query string url |
|
|
 Centurion
Joined: 14 Jan 2008 Posts: 124
|
Hi,
I have several flow that would get the message as a query string.
I need to form an xml from this query string like, say the query string url be
http://localhost:7080/mysampleflow?valueA=1000016378045&ValueB=10
From this i want to form the XML message like
<message>
<valueA>1000016378045</valueA>
<valueB>10</valueB>
</message>
In this the tag names (valueA and valueB) will change in each query string and in the xml as well.
Is is possible to create the XML tag names dynamically in the SET statement.?
-GemZ |
|
Back to top |
|
 |
elvis_gn |
Posted: Tue Oct 14, 2008 9:34 am Post subject: Re: To form XML from query string url |
|
|
 Padawan
Joined: 08 Oct 2004 Posts: 1905 Location: Dubai
|
Hi Gemz,
Gemz wrote: |
Is is possible to create the XML tag names dynamically in the SET statement.? |
Yes, you could use the {variable} in your set statements with the 'variable' holding the tag name.
Else you could also do a CREATE FIELD with the NAME clause.
Regards. |
|
Back to top |
|
 |
kimbert |
Posted: Wed Oct 15, 2008 1:44 am Post subject: |
|
|
 Jedi Council
Joined: 29 Jul 2003 Posts: 5542 Location: Southampton
|
This has cropped up before. Your options are:
- Parse the query string using ESQL. Use CREATE statements to generate the output message tree with the correct names.
- Create a message set containing a tagged delimited message. Set Tag Data Separator to '=', delimiter to '&' . This technique will naturally cope with unexpected property names by automatically creating a self-defining element with the same name as the tag. Alternatively, you could flag up unexpected property names by switching on validation.
Your choice, really. ESQL is simpler, message set approach is easier to extend. |
|
Back to top |
|
 |
Gemz |
Posted: Wed Oct 15, 2008 9:07 am Post subject: |
|
|
 Centurion
Joined: 14 Jan 2008 Posts: 124
|
Kimbert,
Do you mean to use the CREATE statement step by step to generate the ouput message tree.
I thought to put this in while loop like
Quote: |
SET andsignposition = POSITION('&' IN mystrmessage FROM 1);
SET equalsignpostion = POSITION('=' IN mystrmessage FROM 1);
DECLARE textname CHARACTER;
DECLARE textvalue CHARACTER;
DECLARE text CHARACTER;
WHILE ((andsignposition > 0 OR equalsignpostion > 0) AND (andsignposition IS NOT NULL)) DO
IF (andsignposition > 0 ) THEN
SET text = SUBSTRING(mystrmessage FROM 1 FOR andsignposition-1);
SET textname = SUBSTRING(text FROM 1 FOR equalsignpostion-1);
SET textvalue = SUBSTRING(text FROM equalsignpostion+1);
SET OutputRoot.XMLNSC.message.{textname} = textvalue;
SET mystrmessage = SUBSTRING(mystrmessage FROM andsignposition+1);
SET andsignposition = POSITION('&' IN mystrmessage FROM 1);
SET equalsignpostion = POSITION('=' IN mystrmessage FROM 1);
ELSE
SET text = mystrmessage;
SET textname = SUBSTRING(text FROM 1 FOR equalsignpostion-1);
SET textvalue = SUBSTRING(text FROM equalsignpostion+1);
SET OutputRoot.XMLNSC.message.{textname} = textvalue;
SET mystrmessage = SUBSTRING(mystrmessage FROM andsignposition+1);
SET andsignposition = POSITION('&' IN mystrmessage FROM 1);
SET equalsignpostion = POSITION('=' IN mystrmessage FROM 1 REPEAT 2);
END IF;
END WHILE; |
|
|
Back to top |
|
 |
kimbert |
Posted: Wed Oct 15, 2008 10:59 am Post subject: |
|
|
 Jedi Council
Joined: 29 Jul 2003 Posts: 5542 Location: Southampton
|
Quote: |
Do you mean to use the CREATE statement step by step to generate the ouput message tree. |
Yes, that is what I meant. I never use {variable} when I can use CREATE, but that's just my preference. So instead of
Code: |
SET OutputRoot.XMLNSC.message.{textname} = textvalue;
|
I would usually write
Code: |
CREATE LASTCHILD OF OutputRoot.XMLNSC.message NAME textName VALUE textValue; |
|
|
Back to top |
|
 |
Gaya3 |
Posted: Wed Oct 15, 2008 7:31 pm Post subject: |
|
|
 Jedi
Joined: 12 Sep 2006 Posts: 2493 Location: Boston, US
|
kimbert wrote: |
Quote: |
Do you mean to use the CREATE statement step by step to generate the ouput message tree. |
Yes, that is what I meant. I never use {variable} when I can use CREATE, but that's just my preference. So instead of
Code: |
SET OutputRoot.XMLNSC.message.{textname} = textvalue;
|
I would usually write
Code: |
CREATE LASTCHILD OF OutputRoot.XMLNSC.message NAME textName VALUE textValue; |
|
Kimbert,
Which one is good in performance aspect, first or the second, _________________ Regards
Gayathri
-----------------------------------------------
Do Something Before you Die |
|
Back to top |
|
 |
kimbert |
Posted: Thu Oct 16, 2008 12:49 am Post subject: |
|
|
 Jedi Council
Joined: 29 Jul 2003 Posts: 5542 Location: Southampton
|
Good question, but I don't know the answer. I expect MGK will be able to tell us. |
|
Back to top |
|
 |
mgk |
Posted: Thu Oct 16, 2008 2:13 am Post subject: |
|
|
 Padawan
Joined: 31 Jul 2003 Posts: 1642
|
Quote: |
I expect MGK will be able to tell us |
They are performing the same task, and therefore I would expect them to be almost the same in performance terms in this case. However, CREATE XXXCHILD does not seach through any existing elements as SET has to do see if it can find an existing element of the same name to overwrite the value, before it creates a new elements, so if you have a large tree and you always want to create, it can name a difference there...
Regards, _________________ MGK
The postings I make on this site are my own and don't necessarily represent IBM's positions, strategies or opinions. |
|
Back to top |
|
 |
|