Posted: Wed Jun 28, 2006 7:42 pm Post subject: how to add a new fld in the output xml pub/sub
Acolyte
Joined: 08 Jun 2004 Posts: 64
please teach me how to insert a new field in the xml output msg in pubsub using wmqi 2.1 ?
I have this simple code in the compute node which extracts the last closing tag as TOPIC
then pass the entire input XML msg thru without any change to the Output and it works ok
-- code begins----
DECLARE C INTEGER;
SET C = CARDINALITY(InputRoot.*[]);
DECLARE I INTEGER;
SET I = 1;
WHILE I < C DO
SET OutputRoot.*[I] = InputRoot.*[I];
SET I=I+1;
END WHILE;
-- Enter SQL below this line. SQL above this line might be regenerated, causing any modifications to be lost.
SET OutputRoot.MQMD.Format = 'MQHRF2 ' ;
Set OutputRoot.MQRFH2.(MQRFH2.Field)CodedCharSetId = 1208;
Set OutputRoot.MQRFH2.(MQRFH2.Field)Encoding = 546;
Set OutputRoot.MQRFH2.(MQRFH2.Field)Format = 'MQSTR ';
SET OutputRoot.MQRFH2.psc.Command='Publish';
DECLARE CNT INTEGER;
DECLARE TOPIC CHARACTER;
SET CNT = CARDINALITY(InputRoot.XML.*[]);
-- topic is the last root tag in the tree
SET TOPIC = FIELDNAME(InputRoot.XML.*[CNT]);
IF TOPIC = '' THEN
SET TOPIC = FIELDNAME(InputRoot.XML.*[CNT-1]);
END IF;
SET OutputRoot.MQRFH2.psc.Topic='application/testtopic/' || TOPIC;
SET OutputRoot.XML = InputBody;
--code ends
-------This is my current input and output message ------
<employeeinfo>
<name>John Smith </name>
<address> 123 Bell st </address>
</employeeinfo>
---------------------------------------------
This is my question
I would like to add one extra field to the output message to be like this
<employeeinfo>
<name>John Smith </name>
<address>123 Bell st </address>
<country>ca</country>
</<employeeinfo>
and
WITHOUT hardcoding the 'employeeinfo ' in the
SET OutputRoot.XML.employeeinfo.country
that is
I would like to avoid hardcoding 'employeeinfo' using this statement below if possible
SET OutputRoot.XML.employeeinfo.country ='ca';
The reason I would like to avoid hardcoding 'employeeinfo' because employeeinfo is a value extracted from the input message and it changes
for different input messages
I also tried this but run into error
EVAL('SET OutputRoot.XML.'|| TOPIC || '.country' = 'ca');
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