Skip to main content

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.

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)

 

<parent>
<child>
<name></name>
</child>
<bank_account_number></bank_account_number>
</parent>

 


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:

Name(/*)

 


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.


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="efilepath]" />
<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="exname]" />
</arc:call>

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

 

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

 

 


Reply