Sidebar

How Do I Replace A Node When Looping Through Groups Of Nodes

0 votes
59 views
asked Apr 20 by chris-m-3214 (320 points)
edited Apr 20 by chris-m-3214
I have used the technique in this question, https://www.qvera.com/kb/index.php/824/how-can-create-my-own-custom-hl7-xml-csv-message-model-object, to create a new message object model.  However, using the technique on that question creates a new node in the original message and doesn't replace it.  How do I replace the original node with my newly created node?  I had thought of starting with a count of my node groups and then removing the original groups after processing the entire message but some of my messages can contain thousands of nodes and this seems very inefficient.

1 Answer

0 votes
 
Best answer

It's a bit difficult to give a specific answer without seeing your code; however, in the linked article the message.addChild() call adds a child node to the original message.  To replace an existing node, would probably want to do something with message.setNode() instead.

For example, if you wanted to replace the ORC-1 field, you would do this:

message.setNode('ORC-1', 'New data');

Note that message.setNode() accepts an instance, so if you wanted to replace the second ORC-1 field, you would do this:

message.setNode('ORC-1', 'New data', 2);

Using that in a loop is simply a matter of replacing the '2' above with the variable that gets incremented in your loop (in the linked article, the variable is called i ).

Feel free to contact support@qvera.com if you'd like to take a look at your specific channel.

answered Apr 20 by jon-t-7005 (4,990 points)
selected Apr 20 by chris-m-3214
...