Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn more

View all

Sign in to view all badges

Adding node(s) to XML process variable

Anonymous
Not applicable

I have a process with an XML variable, i.e.

var myXML = <package>

                        <assets>

                            <foo name="A">....</foo>

                            <foo name="B">....</foo>

                            <foo name="C">....</foo>

                         </assets>

                  </package>

and I need to add an additional subtree <foo name="D">...</foo> to this variable under /package/assets/.

I am trying to use SetValue but cannot get it to work.

What's the best way to do this?

1 Reply
_hussam_
Level 3
Level 3

Hi,

I did this befor but I do not know if it is th e"best way", what I did is simply cut and paste, substirng and concatenate.

let me show you an example:

in a SetValue use the following variables and their values (expressions)

/process_data/xmlVar1         deserialize('<package> <assets> <foo name="A">....</foo> <foo name="B">....</foo>

                                        <foo name="C">....</foo> </assets> </package>')

/process_data/@strXmlVar      serialize(/process_data/xmlVar1, true)


/process_data/@strNewXml      '<foo name="D">....</foo>'

/process_data/@strXmlVar      concat(substring-before(/process_data/@strXmlVar,

                                    "</assets>"),/process_data/@strNewXml,

                                    "</assets>",substring-after(/process_data/@strXmlVar, "</assets>"))

/process_data/xmlNewVar       deserialize(/process_data/@strXmlVar)

Regards

Hussam