# Problem generating an XML

**URL:** https://community.mp3tag.de/t/problem-generating-an-xml/16659
**Category:** Export
**Created:** [March 5, 2015, 11:45am UTC](https://community.mp3tag.de/t/problem-generating-an-xml/16659 "2015-03-05T11:45:57Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![dario](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/d/bc79bd/32.png) [@dario](https://community.mp3tag.de/u/dario)
#### Post date: [March 5, 2015, 11:45am UTC](https://community.mp3tag.de/t/problem-generating-an-xml/16659/1 "2015-03-05T11:45:57Z")

</div>

Hi everyone,  
sorry for the very generic title, but it's hard to explain my problem with few words.

I need to generate an XML file, but I'm stuck with a problem:

I have a publisher tag in the form "A, B" (without quotes)  
and a composer tag in the form "a, b" (without quotes)

The desired output is:

A a A b B a B b

Thanks For the help

---

<div class="post-metadata">

### Author: ![DetlevD](https://community.mp3tag.de/user_avatar/community.mp3tag.de/detlevd/32/123_2.png) [@DetlevD](https://community.mp3tag.de/u/DetlevD)
#### Post date: [March 5, 2015, 3:20pm UTC](https://community.mp3tag.de/t/problem-generating-an-xml/16659/2 "2015-03-05T15:20:12Z")

</div>

> [@dario](#):
>
> Hi everyone, sorry for the very generic title, but it's hard to explain my problem with few words. ...

Has the problem to do ...  
with the markup language "XML"  
or ...  
with the scripting language "Mp3tag Export scripting language" ...  
and there maybe with the creation of several user-defined variables?

For the latter case ...  
use the functions $put() ... or ... $puts() ... and $get() ...  
from the "Mp3tag Export Scripting Language" ...  
and some other functions from the "Mp3tag Scripting Language".

The problem, if there any, can be resolved kinda like this example ...

**Note: I use this arrow \<== with the meaning of an action "Format value" to fill a tag-field with a text constant. I use this arrow ==\> with the meaning of showing the content from the variable. Mp3tag Scripting Language Tag-Field \<== Value TMP01 \<== 'A, B' TMP02 \<== 'C, D' TMP11 \<== $left(%TMP01%,$sub($strstr(%TMP01%,', '),1)) TMP12 \<== $cutLeft(%TMP01%,$add($strstr(%TMP01%,', '),1)) TMP21 \<== $left(%TMP02%,$strstr(%TMP02%,', ')) TMP22 \<== $cutLeft(%TMP02%,$add($strstr(%TMP02%,', '),1)) %TMP11%', 'TMP21 ==\> 'A, C' %TMP11%', 'TMP22 ==\> 'A, D' %TMP12%', 'TMP21 ==\> 'B, C' %TMP12%', 'TMP22 ==\> 'B, D' Mp3tag Export Scripting Language $put(TMP01,'A, B') $put(TMP02,'C, D') $get(TMP01) ==\> 'A, B' $get(TMP02) ==\> 'C, D' $put(TMP11,$left($get(TMP01),$sub($strstr($get(TMP01),', '),1))) $put(TMP12,$cutLeft($get(TMP01),$add($strstr($get(TMP01),', '),1))) $put(TMP21,$left($get(TMP02),$strstr($get(TMP02),', ')) $put(TMP22,$cutLeft($get(TMP02),$add($strstr($get(TMP02),', '),1)) $get(TMP11) ==\> 'A' $get(TMP12) ==\> 'B' $get(TMP21) ==\> 'C' $get(TMP22) ==\> 'D'**

DD.20150305.1720.CET

---

<div class="post-metadata">

### Author: ![dario](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/d/bc79bd/32.png) [@dario](https://community.mp3tag.de/u/dario)
#### Post date: [March 5, 2015, 3:31pm UTC](https://community.mp3tag.de/t/problem-generating-an-xml/16659/3 "2015-03-05T15:31:13Z")

</div>

> [@DetlevD](#):
>
> Has the problem to do ...  
> with the markup language "XML"  
> or ...  
> with the scripting language "Mp3tag Esport scripting language" ...  
> and there maybe with the creation of several user-defined variables?
> 
> For the latter case ...  
> use the functions $put() ... or ... $puts() ... and $get() ...  
> from the "Mp3tag Esport Scripting Language" ...  
> and some other functions from the "Mp3tag Scripting Language".
> 
> The problem, if there any, can be resolved kinda like this example ...
> 
> **Note: I use this arrow \<== with the meaning of an action "Format value" to fill a tag-field with a text constant. I use this arrow ==\> with the meaning of showing the content from the variable. Mp3tag Scripting Language Tag-Field \<== Value TMP01 \<== 'A, B' TMP02 \<== 'C, D' TMP11 \<== $left(%TMP01%,$sub($strstr(%TMP01%,', '),1)) TMP12 \<== $cutLeft(%TMP01%,$add($strstr(%TMP01%,', '),1)) TMP21 \<== $left(%TMP02%,$strstr(%TMP02%,', ')) TMP22 \<== $cutLeft(%TMP02%,$add($strstr(%TMP02%,', '),1)) %TMP11%', 'TMP21 ==\> 'A, C' %TMP11%', 'TMP22 ==\> 'A, D' %TMP12%', 'TMP21 ==\> 'B, C' %TMP12%', 'TMP22 ==\> 'B, D' Mp3tag Export Scripting Language $put(TMP01,'A, B') $put(TMP02,'C, D') $get(TMP01) ==\> 'A, B' $get(TMP02) ==\> 'C, D' $put(TMP11,$left($get(TMP01),$sub($strstr($get(TMP01),', '),1))) $put(TMP12,$cutLeft($get(TMP01),$add($strstr($get(TMP01),', '),1))) $put(TMP21,$left($get(TMP02),$strstr($get(TMP02),', ')) $put(TMP22,$cutLeft($get(TMP02),$add($strstr($get(TMP02),', '),1)) $get(TMP11) ==\> 'A' $get(TMP12) ==\> 'B' $get(TMP21) ==\> 'C' $get(TMP22) ==\> 'D'**
> 
> DD.20150305.1720.CET

Hey thanks for the quick answer!  
Yes, it's a problem with mp3tag export scripting language.

I realize now that I wasn't very clear while explaining my problem, I'm very sorry.

The real problem is that I don't know beforehand how many publishers and composers I'll have!  
So it could be  
'A, B' and 'a, b'  
but it could also be  
'A, B, C' and 'a'  
or  
'A, B,' and 'a, b, c, d'

---

<div class="post-metadata">

### Author: ![DetlevD](https://community.mp3tag.de/user_avatar/community.mp3tag.de/detlevd/32/123_2.png) [@DetlevD](https://community.mp3tag.de/u/DetlevD)
#### Post date: [March 5, 2015, 3:41pm UTC](https://community.mp3tag.de/t/problem-generating-an-xml/16659/4 "2015-03-05T15:41:02Z")

</div>

> [@dario](#):
>
> ... I realize now that I wasn't very clear while explaining my problem, I'm very sorry. The real problem is that I don't know beforehand how many publishers and composers I'll have! ...

I do expect a problem for you, if you want to create and handle all the possible _permutations_ of Publishers and Composers.  
And for what should it be worth?

Or do I misunderstand the problem?  
Maybe you only want to get each single item from a list of items?  
But there is no loop or foreach instruction, which works directly on the content of a tag-field, ...  
therefore you have to do it the hard way, extract each single item from the itemlist, which is stored within one tag-field, step by step.

For example ... you can count the commas within a string (3 commas = 4 items), ...  
and then decide, using $if, which case of a set of prepared cases, is able to handle this number of items.

For example ... you can try this sort of regular expression ...

**$regexp('Aaa, Bbb, Ccc, Ddd, ','^(?:.+?, ){0}(.+?), (?:.+, )\*$','$1') ==\> 'Aaa' $regexp('Aaa, Bbb, Ccc, Ddd, ','^(?:.+?, ){1}(.+?), (?:.+, )\*$','$1') ==\> 'Bbb' $regexp('Aaa, Bbb, Ccc, Ddd, ','^(?:.+?, ){2}(.+?), (?:.+, )\*$','$1') ==\> 'Ccc' $regexp('Aaa, Bbb, Ccc, Ddd, ','^(?:.+?, ){3}(.+?), (?:.+, )\*$','$1') ==\> 'Ddd'**

DD.20150305.1854.CET

Hmm, here is another idea, ...  
how to split an itemlist into single addressable items, ...  
by creating a multi-value tag-field from the tag-field, which contains the string with the itemlist.

1. Copy the existing content from COMPOSER to new tag-field COMPOSER\_META, ...  
e. g. the list of items is 'Aaa, Bbb, Ccc, Ddd'

2. Run Action "Split field by separator", ...  
Field: COMPOSER\_META  
Split character: ,

3. Then there exists a multi-value tag-field COMPOSER\_META.  
COMPOSER\_META = 'Aaa'  
COMPOSER\_META = 'Bbb'  
COMPOSER\_META = 'Ccc'  
COMPOSER\_META = 'Ddd'

Each value can be accessed directly by using the function $meta.  
$meta(COMPOSER\_META,0) ==\> 'Aaa'  
$meta(COMPOSER\_META,1) ==\> 'Bbb'  
$meta(COMPOSER\_META,2) ==\> 'Ccc'  
$meta(COMPOSER\_META,3) ==\> 'Ddd'

This might be useful when creating an export script, ...  
which probably can have simpler coding needed than the $regex proposal.

After creating the report, the multi-value tag-field COMPOSER\_META can be removed from the tag, using the ...  
Action "Remove fields"  
Field: COMPOSER\_META

DD.20150305.2109.CET

---

<div class="post-metadata">

### Author: ![dario](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/d/bc79bd/32.png) [@dario](https://community.mp3tag.de/u/dario)
#### Post date: [March 5, 2015, 5:15pm UTC](https://community.mp3tag.de/t/problem-generating-an-xml/16659/5 "2015-03-05T17:15:49Z")

</div>

> [@DetlevD](#):
>
> I do expect a problem for you, if you want to create and handle all the possible _permutations_ of Publishers and Composers.  
> And for what should it be worth?
> 
> Or do I misunderstand the problem?  
> Maybe you only want to get each single item from a list of items?  
> But there is no loop or foreach instruction, which works directly on the content of a tag-field, ...  
> therefore you have to do it the hard way, extract each single item from the itemlist, which is stored within one tag-field, step by step.
> 
> For example ... you can count the commas within a string (3 commas = 4 items), ...  
> and then decide, using $if, which case of a set of prepared cases, is able to handle this number of items.
> 
> For example ... you can try this sort of regular expression ...
> 
> **$regexp('Aaa, Bbb, Ccc, Ddd, ','^(?:.+?, ){0}(.+?), (?:.+, )\*$','$1') ==\> 'Aaa' $regexp('Aaa, Bbb, Ccc, Ddd, ','^(?:.+?, ){1}(.+?), (?:.+, )\*$','$1') ==\> 'Bbb' $regexp('Aaa, Bbb, Ccc, Ddd, ','^(?:.+?, ){2}(.+?), (?:.+, )\*$','$1') ==\> 'Ccc' $regexp('Aaa, Bbb, Ccc, Ddd, ','^(?:.+?, ){3}(.+?), (?:.+, )\*$','$1') ==\> 'Ddd'**
> 
> DD.20150305.1854.CET

Yes, I need to handle all the possible permutations...  
"luckily" I think it's limited to 4 elements at most, but I wanted to avoid having to write all the possible cases if possible.  
Thanks for the help 🙂

---

<div class="post-metadata">

### Author: ![DetlevD](https://community.mp3tag.de/user_avatar/community.mp3tag.de/detlevd/32/123_2.png) [@DetlevD](https://community.mp3tag.de/u/DetlevD)
#### Post date: [March 5, 2015, 6:12pm UTC](https://community.mp3tag.de/t/problem-generating-an-xml/16659/6 "2015-03-05T18:12:27Z")

</div>

> [@dario](#):
>
> Yes, I need to handle all the possible permutations...

Please explain, what should be the purpose of _permutations_ in practice ...  
which means all possible pairs of publishers and composers, this is crazy???  
For a given 4x4 relation, that are 1_2_3\*4 = 24 cases.

I assume, you simply want to extract each publisher from an itemlist of publishers ...  
and want to print out this publisher.

I assume, you simply want to extract each composer from an itemlist of composers ...  
and want to print out this composer.

DD.20150305.2012.CET

---

<div class="post-metadata">

### Author: ![dario](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/d/bc79bd/32.png) [@dario](https://community.mp3tag.de/u/dario)
#### Post date: [March 5, 2015, 6:23pm UTC](https://community.mp3tag.de/t/problem-generating-an-xml/16659/7 "2015-03-05T18:23:34Z")

</div>

Yes, it's crazy. But I need to generate an XML that has to be sent to an online service, and they want that format ☹

---

<div class="post-metadata">

### Author: ![DetlevD](https://community.mp3tag.de/user_avatar/community.mp3tag.de/detlevd/32/123_2.png) [@DetlevD](https://community.mp3tag.de/u/DetlevD)
#### Post date: [March 5, 2015, 6:29pm UTC](https://community.mp3tag.de/t/problem-generating-an-xml/16659/8 "2015-03-05T18:29:20Z")

</div>

Now I know that you don't know what a _permutation_ is. ![:blush:](https://community.mp3tag.de/uploads/default/original/1X/c5a064300f7d900a70c2196f6eee95e32dde9b52.gif ":blush:")

DD.20150305.2029.CET
