Skip to main content
Solved

Get a filename part while mapping XML

  • May 2, 2023
  • 5 replies
  • 218 views

Forum|alt.badge.img

Hello,

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

If you are looking to get the 1234 portion of that filename, you can use the split formatter (https://cdn.cdata.com/help/AZH/mft/String-Formatters.html#splitdelimiter-indextoreturn) 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?

This topic has been closed for replies.

5 replies

Forum|alt.badge.img
  • Employee
  • Answer
  • May 2, 2023

If you are looking to get the 1234 portion of that filename, you can use the split formatter (https://cdn.cdata.com/help/AZH/mft/String-Formatters.html#splitdelimiter-indextoreturn) 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?


Forum|alt.badge.img
  • Author
  • Apprentice
  • May 3, 2023

Yes, thank you for your help!


Forum|alt.badge.img
  • Apprentice
  • January 29, 2024

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?


Forum|alt.badge.img
  • Employee
  • January 29, 2024

@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:

 

[_message.header:FileName]

 

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:

 


Forum|alt.badge.img
  • Apprentice
  • January 29, 2024

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!