Get a filename part while mapping XML

  • 2 May 2023
  • 5 replies

Userlevel 2


I need to get a specific filename part value while mapping XML to the desired structure in the XMLMap connector. F. ex. I need to extract ‘1234’ part from a file name 1234_abcd.xml.

I have tried to write an expression in the Expression Editor: [getfilename(substring(0, indexof(filename(), "_")))]

It does not work and I am not sure that is wrong.

Any ideas? Maybe there are even better solutions?


Best answer by Charlie S 2 May 2023, 17:25

View original

5 replies

Userlevel 3

If you are looking to get the 1234 portion of that filename, you can use the split formatter ( to split on the underscore character in the filename and return the first substring that resulted from the split.

Like this:

[filename | split(‘_’1)]

This expression would resolve to the value of “1234”.

Does this work for you?

Userlevel 2

Yes, thank you for your help!

Userlevel 1

I have a similar problem, and there seems to be no way to retrieve the name of the file being processed inside an XML Map connector

If I use this:

<arc:set attr="result.text">[filename | split('_'1)]</arc:set>

or this.

<arc:set attr="result.text">[filename]</arc:set>

The result is always an error.
"The attribute does not exist. This formatter cannot be called with nonexistent attributes."

Can i ask if you can share the exact code used to solve your problem?

Userlevel 3

@AndreaMassa The reason why you are seeing that exception is because the script nodes inside of XML Map do not support the [FileName] attribute. Instead, you will want to target the actual FileName header itself, which is stored on the _message item, like this:




This will evaluate to the name of the input file. However, I noticed you are using a script node for this and while this will work, it isn’t necessary. You can evaluate the name of the input file and apply any formatters to it within the expression editor for the desired node. This would be the recommended approach:


Userlevel 1

Many thanks, I really would never have gotten there. I spent hours trying to figure out how to do this. I was starting to suspect that I had to get the information some other way. Unfortunately I looked for documentation or other examples but I never came across an example like the one you wrote to me.

Many thanks again.
I update my ticket so there is a trace!