Possible to get element name via xpath

  • 26 July 2023
  • 4 replies


Is it possible to use the xpath formatter to get the name of the current element?

Currently I am interested to get the name of the root element and get the content of an attribute on said element.


Best answer by James B 4 August 2023, 16:30

View original

4 replies

Userlevel 3
Badge +1

Are you doing this in an XML Map connector?


You can use the relative  “..” notation to traverse up the XML tree and back down again.


So if you are in /parent/child/name  you can use xpath(../../bank_account_number)





Thank you for your reply. It is not entirely what I am looking for. 
we are processing multiple types of xmls and I would like to get the name of the outermost element to use in a branch connector to determine the correct flow.  In regular XPath you would use:



Userlevel 3
Badge +1

I often use a Message Header for this sort of process. Maybe check if a node exists and set the a message header called something like “rootNodeName”. You would do this in a Script connector, probably using <arc:select>, <arc:case> and an xmlDOMSearch operation.

 You can then use one or more Branch connectors later in the flow to check the “rootNodeName” header and route accordingly.

Userlevel 4

In ArcScript, there is an xname function, similar to xpath, which will resolve the name of the element that you are looping on. 


If you want a script that will determine the root element of an input XML file and promote it as a header on the message:


<arc:set attr="xml.uri" value="[filepath]" />
<arc:set attr="xml.xpath" value="/" />

<!-- the xname function evaluates the name of the current element -->
<arc:call op="xmlDOMSearch" item="xml">
<arc:set attr="output.header:XMLRoot" value="[xname]" />

<!-- include the original file -->
<arc:set attr="output.filepath" value="[filepath]" />
<arc:push item="output" />


This should then add a header of XMLRoot to the output: