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
Bedrock Mission!

Learn more

View all

Sign in to view all badges

Adding a node through XPath

Avatar

Level 6
I need to add an item into my XML.


user1


to


user1
user2


I thought I read where I could just set a value to the new index: Approvers/Approver[2]/ApproverID="user2"

That is not working though.
7 Replies

Avatar

Level 10
Nope the Approver[2] node must exist for that to happen. You can replace nodes that exist so if you changed the Approvers node with the new XML then you would get your desired result.

Avatar

Level 6
I need the old data plus the new so I end up with the same problem creating the new XML. My work around is to do it with Strings then replace, but it is messy.

Avatar

Level 6
Hi,

I need something similar: I have a document var with a xml document. I need to take part of that xml (a specific nodeset) and add it to a string.



any ideas to acomplish this?



thank you

Avatar

Level 10
First you want to put the content of the document into a XML var so you can use xPath.



You can use xPath to get to the node you want (ex. /process_data/myXMLVar/Root/Customers).



Then use the serialize function from the xPath editor (under Misc) to convert the nodes into a string:



serialize(/process_data/myXMLVar/Root/Customers)



Finally you can use the concat function from the xPath editor (under string) to merge two strings together:



concat(/process_data/@myStringVar, serialize(/process_data/myXMLVar/Root/Customers))



Jasmin

Avatar

Level 10
A node can be added to an XML instance using XSL in an XSLT Transform service, also.

My sample process uses two input process variables:

1. 'inputXml' of type xml


user1


2. 'approverId' of type string

foobar

I define the following XSLT template which consumes the input process variable 'approverId':



ApproverID
{$ /process_data/@approverId $}









The result of the applying the XSL is as follows:



user1


foobar



The process could be designed to iterate over the input XML and the XSL.

Steve