# Get a filename part while mapping XML

**URL:** <https://community.cdata.com/t/get-a-filename-part-while-mapping-xml/173>\
**Category:** CData Arc\
**Tags:** question\
**Created:** [May 2, 2023, 12:51pm UTC](https://community.cdata.com/t/get-a-filename-part-while-mapping-xml/173 "2023-05-02T12:51:49Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![EdiSupportGir](https://avatars.discourse-cdn.com/v4/letter/e/898d66/32.png) [@EdiSupportGir](https://community.cdata.com/u/EdiSupportGir)\
**Post date:** [May 2, 2023, 12:51pm UTC](https://community.cdata.com/t/get-a-filename-part-while-mapping-xml/173/1 "2023-05-02T12:51:49Z")

</div>

Hello,

I need to get a specific filename part value while mapping XML to the desired structure in the&nbsp;XMLMap connector.&nbsp;F. ex. I need to extract ‘1234’ part from a file&nbsp;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?

---

<div class="post-metadata">

**Author:** ![Charlie\_S](https://avatars.discourse-cdn.com/v4/letter/c/c68b51/32.png) [@Charlie\_S](https://community.cdata.com/u/Charlie_S)\
**Post date:** [May 2, 2023, 3:25pm UTC](https://community.cdata.com/t/get-a-filename-part-while-mapping-xml/173/2 "2023-05-02T15:25:29Z")

</div>

If you are looking to get the 1234 portion of that filename, you can use the split formatter ([CData Arc - String Formatters | Version 22.0.8473](https://cdn.cdata.com/help/AZH/mft/String-Formatters.html#splitdelimiter-indextoreturn)) to split on the underscore character in the filename and return the&nbsp;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?

---

<div class="post-metadata">

**Author:** ![EdiSupportGir](https://avatars.discourse-cdn.com/v4/letter/e/898d66/32.png) [@EdiSupportGir](https://community.cdata.com/u/EdiSupportGir)\
**Post date:** [May 3, 2023, 7:35am UTC](https://community.cdata.com/t/get-a-filename-part-while-mapping-xml/173/3 "2023-05-03T07:35:42Z")

</div>

Yes, thank you for your help!

---

<div class="post-metadata">

**Author:** ![AndreaMassa](https://avatars.discourse-cdn.com/v4/letter/a/8491ac/32.png) [@AndreaMassa](https://community.cdata.com/u/AndreaMassa)\
**Post date:** [January 29, 2024, 2:02pm UTC](https://community.cdata.com/t/get-a-filename-part-while-mapping-xml/173/4 "2024-01-29T14:02:37Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Charlie\_S](https://avatars.discourse-cdn.com/v4/letter/c/c68b51/32.png) [@Charlie\_S](https://community.cdata.com/u/Charlie_S)\
**Post date:** [January 29, 2024, 2:44pm UTC](https://community.cdata.com/t/get-a-filename-part-while-mapping-xml/173/5 "2024-01-29T14:44:31Z")

</div>

@AndreaMassa &nbsp;The reason why you are seeing that exception is because the script nodes inside of XML Map do not support the [FileName] attribute. Instead,&nbsp;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:

 ![f1427233-d58f-44ad-93df-021aa5ce63db.png](https://us1.discourse-cdn.com/cdata/original/1X/99e87447fde1c4ddc2cb9342a8614e871feb3670.png)

---

<div class="post-metadata">

**Author:** ![AndreaMassa](https://avatars.discourse-cdn.com/v4/letter/a/8491ac/32.png) [@AndreaMassa](https://community.cdata.com/u/AndreaMassa)\
**Post date:** [January 29, 2024, 2:58pm UTC](https://community.cdata.com/t/get-a-filename-part-while-mapping-xml/173/6 "2024-01-29T14:58:54Z")

</div>

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!
