4 Replies Latest reply on May 2, 2017 10:39 PM by BjornEricsson

    Insert node within XML variable?

    BjornEricsson Level 1

      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.

        • 1. Re: Insert node within XML variable?
          James R Green Level 1

          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>
          • 2. Re: Insert node within XML variable?
            BjornEricsson Level 1

            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?

            • 3. Re: Insert node within XML variable?
              BjornEricsson Level 1

              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?

              • 4. Re: Insert node within XML variable?
                lesutton1 Level 1

                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.