How can i generate an XML array

0 votes
asked Sep 6, 2019 by scott-b-8720 (560 points)
When executing the following I get the error indicated.  Can someone point me in the right direction about what I'm missing?

message = qie.createXMLMessage("<case></case>", 'UTF-8');
message.setNode("/case/email", 'scott');
message.setNode('/case/data', '');
message.setNode('/case/data/@type', 'array');

message.setNode('/case/data/item', '', 1, true);
message.setNode('/case/data/item[1]/key', 'key1');
message.setNode('/case/data/item[1]/value', 'value1');

i get this error on the next line: [line: 12] WrappedException: Wrapped com.qvera.qie.web.exception.MessageModelException: Node not found: /case/data/item, instance=1
message.setNode('/case/data/item', '', 2, true);
message.setNode('/case/data/item[2]/@hidden', 'true');

message.setNode('/case/data/item[2]/key', 'key2');
message.setNode('/case/data/item[2]/value', 'value2');

1 Answer

0 votes
The issue is caused by the fact that the second "Item" node does not exist. The setNode adds the first Item node since none exists but one the second one it fails because one already exists. By changing the message.setNode('/case/data/item', '', 2, true); (line 13) to use message.addChild('/case/data', 'item', 'key2'); we can add the second item node and then subsequently set their nodes.
answered Sep 6, 2019 by gary-t-8719 (14,820 points)