Loop through an XML-parent tag and attach all those files to an email

Hi, I want to attach files dynamically to an email, and I don’t know what files it is, how many it is and they are always in their unique folders and with unique names. How can I achieve that and how do i loop through and extract the data I need?

My idea is that my XML-file in the datamapper contains the data I need. For example:

<attachments>
	<attachment>
		<folder>c:/path1/</folder>
		<filename>pp-power.xlsx</filename>
	</attachment>
	<attachment>
		<folder>d:/path2/</folder>
		<filename>planetpress-is-awesome.pdf</filename>
	</attachment>
	<attachment>
		<folder>file://///server/shared-folder/</folder>
		<filename>shared-file.docx</filename>
	</attachment>
</attachments>

I am wondering how the attachment script should be? If i only attach one file on “c:/” with the name “file.txt” it will look like this:
results.append('<link rel="related" href="c:/file.txt">');

If it always was 3 unique files, I could do like below but my issue is that I will sometimes have 1 file and sometimes 20 files.

image

I’m stuck.

I solved it with: https://learn.objectiflune.com/discourse/t/dynamically-add-multiple-attachments-to-email/1841