Looping through a set of XML elements retrieved via Get XML Elements

Hi there,

I am using the ‘Get XML Elements’ task with an xPath similar to this: //element1////@[. = ‘value1’] to retrieve a list of all the attributes that are set to =“value1” in an XML doc. I’m saving that with the output name ‘emptyAttributes’ and when I print ‘emptyAttributes’ to the console I see all the correct matches. However I am having trouble working out how to then loop through that emptyAttributes set and then do a further function on it (e.g. delete that attribute, or update the value to =“foobar” or something).

While looping through the set, I’m setting ‘Current Item Name’ as ‘attribute’ in the loop, then in the Set XML Value operation setting the ‘Node’ to “=attribute” but I have no idea what to enter for the XPath as I don’t know the exact XPath (having got the set emptyAttributes from the Get XML elements operation it could be anything…).

Do I need to do =“attribute.getPath()” or something for the XPath value?


When you get an XML element and provide as the node of an XML operation, the XPath becomes relative to that node, so if you want to refer to that node itself you can simply use a dot “.” or if you want to find a child node called foo you could use “.//foo”

It’s important to note though that if you start the XPath with a “/” the XPath is absolute rather than relative so will be evaluated with the document root node as the starting point.

Anyway in your case you might want to do something like:

“Get XML Elements” Node="=xmlDoc" XPath="//element1////@[. = ‘value1’]" Output Name=“emptyAttributes”
“Loop Through Set” Set=“emptyAttributes” Current Item Name=“attribute”
----“Remove XML Node” Node=“attribute” XPath="."

1 Like

Cool thanks, that’s working for me.