Highlighted

Insert node within XML variable?

BjornEricsson1

24-04-2017

How do I specify the Location within an XML variable so that the XML selected by the expression will append this data?

I tried /process_data/TestXML/*/*[last()] as Location, but that replaced the selected node, not appended after.

Replies

Highlighted

James_R_Green

02-05-2017

Hi,

 
If I have understood your question correctly, you should be able to add a node by referencing it by name (even though it doesn't exist yet) and setting it to a value for example:
 
/process_data/testXML =
 
<test>
<field1>a</field1>
<field2>b</field2>
<field3>c</field3>
</test>
 
If we add "SetValue" activity to our process with the following settings:
 
Location /process_data/testXML/test/field4  Expression "new value"
 
 
testXML would then equal:
 
<test>
<field1>a</field1>
<field2>b</field2>
<field3>c</field3>
        <field4>new value</field4>
</test>
Highlighted

BjornEricsson1

02-05-2017

Thanks, but there might already be a node called testXML/test/field4 that I then would replace. I need to  insert a new one without replacing any old ones. Does that explenation make sese?

Highlighted

BjornEricsson1

02-05-2017

Thanks, but there might already be a node called testXML/test/field4 that I then would replace. I need to  insert a new one without replacing any old ones. Does that explenation make sese?

Highlighted

lesutton1

03-05-2017

Bjorn, if you want to insert nodes, then I'd recommend going straight to the script component, or alternatively create your own custom DSC JAR that allows you to insert, and remove nodes. If you do know how many nodes you have in your XML, adding a node via /VariableName/NodeName[1] will create a new node for you. Again, custom DSC will allow you much more flexibility when it comes to manipulating XML.