Author |
Message
|
lanny boy |
Posted: Tue May 18, 2004 1:00 am Post subject: XML - Conversion of simple type to attribute of complex????? |
|
|
Voyager
Joined: 24 Nov 2003 Posts: 79 Location: UK
|
I have an XML structure in the following format
InputRoot.XML.tagA.tagB.field1;
InputRoot.XML.tagA.tagB.field2;
InputRoot.XML.tagA.tagB.field3.... which repeats 100 times to;
....
InputRoot.XML.tagA.tagB.field100;
I need to change the format of the XML so that the simple type XML (above) is converted to an attribute of a new Complex type as below
OutputRoot.XML.tagC.(XML.attr)field1;
OutputRoot.XML.tagC.(XML.attr)field2;
....
OutputRoot.XML.tagC.(XML.attr)field100;
I have tried a number of things to work including the code below:
Set j = Cardinality(InputBody.SWIFT.Block4.*[]);
SET n = 1;
While n <= j do
Set OutputRoot.XML.tagC.(XML.attr)[n] = InputBody.tagA.tagB.[n];
SET n = n +1;
END WHILE;
When viewed in Debug mode the above code does seem to work initially in that the tags are changed and the data is mapped correctly, however upon writing to the output q it fails due to XML writing errors.
Is it possible that WMQSI does not allow dynamic conversion of a simple type and its value to an attribute of another complex type??
Thanks in advance
Lanny |
|
Back to top |
|
 |
kimbert |
Posted: Tue May 18, 2004 2:02 am Post subject: |
|
|
 Jedi Council
Joined: 29 Jul 2003 Posts: 5542 Location: Southampton
|
Quote: |
Is it possible that WMQSI does not allow dynamic conversion of a simple type and its value to an attribute of another complex type?? |
No - the MRM can certainly do this.
1. If you have not done so, create a message set and a message definition describing your input message.
2. Add an XML physical format to describe the input (identifier 'XML_in')
3. Add another XML physical format to describe the output (identifier 'XML_out')
4. In the XML_out properties of your simple elements, set the 'Render' property to 'XMLAttribute'.
5. Using a Compute node, or perhaps an RCD node, simple change the physical format of the message to 'XML_out'. |
|
Back to top |
|
 |
lanny boy |
Posted: Tue May 18, 2004 2:09 am Post subject: |
|
|
Voyager
Joined: 24 Nov 2003 Posts: 79 Location: UK
|
Thanks for that. I was also coming to the conclusion that I would have to create a new message set...
Out of curiosity is it possible to achieve the same thing within a compute node?? |
|
Back to top |
|
 |
kimbert |
Posted: Tue May 18, 2004 2:38 am Post subject: |
|
|
 Jedi Council
Joined: 29 Jul 2003 Posts: 5542 Location: Southampton
|
I don't think you can change an element to an attribute without using MRM XML (i.e. you need to use a message set). |
|
Back to top |
|
 |
fschofer |
Posted: Tue May 18, 2004 3:15 am Post subject: |
|
|
 Knight
Joined: 02 Jul 2001 Posts: 524 Location: Mainz, Germany
|
Hi
this worked for me, i do not know if its the best solution.
I added the IF statement because CARDINALITY also counts the empty
attributes of tagB and the fields
Code: |
DECLARE j INTEGER;
DECLARE n INTEGER;
DECLARE z INTEGER;
SET j = CARDINALITY(InputRoot.XML.tagA.tagB.*[]);
SET n = 1;
SET z = 1;
WHILE n <= j DO
IF FIELDNAME(InputBody.tagA.tagB.*[n]) <> '' THEN
SET OutputRoot.XML.tagC.(XML.attr){FIELDNAME(InputBody.tagA.tagB.*[n])} VALUE = InputBody.tagA.tagB.*[n];
SET z = z + 1;
END IF;
SET n = n +1;
END WHILE; |
Input:
Code: |
<tagA>
<tagB>
<field001>data1</field001>
<field002>data2</field002>
<field003>data3</field003>
<field004>data4</field004>
<field005>data5</field005>
</tagB>
</tagA> |
Output:
Code: |
<tagC field001="data1" field002="data2" field003="data3" field004="data4" field005="data5"/> |
Greetings
Frank |
|
Back to top |
|
 |
lanny boy |
Posted: Tue May 18, 2004 3:29 am Post subject: |
|
|
Voyager
Joined: 24 Nov 2003 Posts: 79 Location: UK
|
Thanks Frank that worked a treat! |
|
Back to top |
|
 |
|