# Possible to get element name via xpath

**URL:** <https://community.cdata.com/t/possible-to-get-element-name-via-xpath/291>\
**Category:** CData Arc\
**Tags:** question\
**Created:** [July 26, 2023, 7:39pm UTC](https://community.cdata.com/t/possible-to-get-element-name-via-xpath/291 "2023-07-26T19:39:41Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Christophe\_K](https://avatars.discourse-cdn.com/v4/letter/c/e9a140/32.png) [@Christophe\_K](https://community.cdata.com/u/Christophe_K)\
**Post date:** [July 26, 2023, 7:39pm UTC](https://community.cdata.com/t/possible-to-get-element-name-via-xpath/291/1 "2023-07-26T19:39:41Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![russell-jerseypost](https://avatars.discourse-cdn.com/v4/letter/r/439d5e/32.png) [@russell-jerseypost](https://community.cdata.com/u/russell-jerseypost)\
**Post date:** [July 27, 2023, 4:19pm UTC](https://community.cdata.com/t/possible-to-get-element-name-via-xpath/291/2 "2023-07-27T16:19:15Z")

</div>

Are you doing this in an XML Map connector?

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

So if you are in /parent/child/name&nbsp; you can use xpath(../../bank\_account\_number)

```xml
<parent> <child> <name></name> </child> <bank_account_number></bank_account_number></parent>

```

---

<div class="post-metadata">

**Author:** ![Christophe\_K](https://avatars.discourse-cdn.com/v4/letter/c/e9a140/32.png) [@Christophe\_K](https://community.cdata.com/u/Christophe_K)\
**Post date:** [July 30, 2023, 5:15am UTC](https://community.cdata.com/t/possible-to-get-element-name-via-xpath/291/3 "2023-07-30T05:15:26Z")

</div>

Thank you for your reply. It is not entirely what I am looking for.&nbsp;  
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.&nbsp;&nbsp;In regular XPath you would use:

```xml
Name(/*)

```

---

<div class="post-metadata">

**Author:** ![russell-jerseypost](https://avatars.discourse-cdn.com/v4/letter/r/439d5e/32.png) [@russell-jerseypost](https://community.cdata.com/u/russell-jerseypost)\
**Post date:** [August 1, 2023, 1:51pm UTC](https://community.cdata.com/t/possible-to-get-element-name-via-xpath/291/4 "2023-08-01T13:51:23Z")

</div>

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&nbsp;using arc:select, arc:case and an&nbsp;xmlDOMSearch operation.

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

---

<div class="post-metadata">

**Author:** ![James\_B](https://sea3.discourse-cdn.com/cdata/user_avatar/community.cdata.com/james_b/32/1688_2.png) [@James\_B](https://community.cdata.com/u/James_B)\
**Post date:** [August 4, 2023, 2:30pm UTC](https://community.cdata.com/t/possible-to-get-element-name-via-xpath/291/5 "2023-08-04T14:30:35Z")

</div>

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:

```xml
<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]" /></arc:call><!-- 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:

![5587613f-6899-4b24-bb82-f7cd6dd5cfc2.png](https://us1.discourse-cdn.com/cdata/original/1X/6830186eb48c1a029bd37c34e59aa0f45ff0f523.png)
