# How to escape ampersands in XML export

**URL:** <https://community.mp3tag.de/t/how-to-escape-ampersands-in-xml-export/18870>\
**Category:** Support\
**Created:** [April 8, 2017, 3:56pm UTC](https://community.mp3tag.de/t/how-to-escape-ampersands-in-xml-export/18870 "2017-04-08T15:56:47Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![romantu](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/r/eb9ed0/32.png) [@romantu](https://community.mp3tag.de/u/romantu)\
**Post date:** [April 8, 2017, 3:56pm UTC](https://community.mp3tag.de/t/how-to-escape-ampersands-in-xml-export/18870/1 "2017-04-08T15:56:47Z")

</div>

First of all, thank you for keeping up the good work on Mp3tag!

I'm currently attempting to export my library as an XML file. Everything works fine for me, except that the resulting XML is not valid when artists have ampersands (&) in their names. I am using Eclipse to validate the XML and the validation error is "_The entity name must immediately follow the '&' in the entity reference. LibraryExport.xml /iTunesPlaylists line 1501 XML Problem_".

Here is how line 1501 looks:

```
<artist>Bryan Adams, Rod Stewart & Sting</artist>

```

The question is, is it possible to escape such characters by changing configuration?

Many thanks for any help!

---

<div class="post-metadata">

**Author:** ![ohrenkino](https://community.mp3tag.de/user_avatar/community.mp3tag.de/ohrenkino/32/4843_2.png) [@ohrenkino](https://community.mp3tag.de/u/ohrenkino)\
**Post date:** [April 8, 2017, 4:06pm UTC](https://community.mp3tag.de/t/how-to-escape-ampersands-in-xml-export/18870/2 "2017-04-08T16:06:37Z")

</div>

> [@Roman T](#):
>
> ...  
> Here is how line 1501 looks:
> 
> ```
> <artist>Bryan Adams, Rod Stewart & Sting</artist>
> 
> ```
> 
> The question is, is it possible to escape such characters by changing configuration?
> 
> Many thanks for any help!

You could change the generating line to  
$replace(%artist%,'&','&')

---

<div class="post-metadata">

**Author:** ![romantu](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/r/eb9ed0/32.png) [@romantu](https://community.mp3tag.de/u/romantu)\
**Post date:** [April 8, 2017, 4:20pm UTC](https://community.mp3tag.de/t/how-to-escape-ampersands-in-xml-export/18870/3 "2017-04-08T16:20:49Z")

</div>

Indeed, this has worked. Thank you very much!

---

<div class="post-metadata">

**Author:** ![Etz](https://community.mp3tag.de/user_avatar/community.mp3tag.de/etz/32/7648_2.png) [@Etz](https://community.mp3tag.de/u/Etz)\
**Post date:** [June 25, 2020, 11:48am UTC](https://community.mp3tag.de/t/how-to-escape-ampersands-in-xml-export/18870/4 "2020-06-25T11:48:51Z")

</div>

But how do you escape multiple?

$replace(%artist%,'&','&') works fine, but as I red from [documentation](https://docs.mp3tag.de/scripting), multiple replacements should be also possible, hence I tried: $replace(%\_path%,'&','&\_amp;',''','&\_apos;') but it only generates [SYNTAX ERROR IN FORMATTING STRING][SYNTAX ERROR IN FORMATTING STRING]

PS: Added underscores, or forum will truncate those.

Idea is to, escape all invalid XML characters on export.  
And I do use ' in tags and filenames.

---

<div class="post-metadata">

**Author:** ![ohrenkino](https://community.mp3tag.de/user_avatar/community.mp3tag.de/ohrenkino/32/4843_2.png) [@ohrenkino](https://community.mp3tag.de/u/ohrenkino)\
**Post date:** [June 25, 2020, 11:59am UTC](https://community.mp3tag.de/t/how-to-escape-ampersands-in-xml-export/18870/5 "2020-06-25T11:59:35Z")

</div>

You can test your expression in Convert\>Tag-Tag.  
This one should be  
`$replace(%title%,'&','&_amp;','',&_apos;)`  
To show code as code, enclose it in accent-grave.

---

<div class="post-metadata">

**Author:** ![Etz](https://community.mp3tag.de/user_avatar/community.mp3tag.de/etz/32/7648_2.png) [@Etz](https://community.mp3tag.de/u/Etz)\
**Post date:** [June 25, 2020, 12:08pm UTC](https://community.mp3tag.de/t/how-to-escape-ampersands-in-xml-export/18870/6 "2020-06-25T12:08:46Z")

</div>

Thank you, but as it turned out replacing ' with &\_apos; is not required for Zune/WMP Playlists...  
Escaping it will render playlist unplayable instead. 😃

Looks like Microsoft follows standards in his usual way...

---

<div class="post-metadata">

**Author:** ![Crissov](https://community.mp3tag.de/user_avatar/community.mp3tag.de/crissov/32/6619_2.png) [@Crissov](https://community.mp3tag.de/u/Crissov)\
**Post date:** [June 25, 2020, 2:13pm UTC](https://community.mp3tag.de/t/how-to-escape-ampersands-in-xml-export/18870/7 "2020-06-25T14:13:01Z")

</div>

You only [need to “escape”](https://docs.mp3tag.de/scripting)with a pair of single quotes `'` – the following characters in Mp3tag scripts:

- `[`, `]` square brackets: `'['` and `']'`
- `(`, `)` round parentheses: `'('` and `')'`
- `$` dollar sign: `'$'`
- `%` percent sign: `'%'`
- `,` comma: `','`
- `'` apostrophe: `''`

Therefore, `$replace(%title%,&,&amp;,'',&apos;)` should work as expected.

---

<div class="post-metadata">

**Author:** ![system](https://community.mp3tag.de/uploads/default/original/2X/c/ce7035d426cb755a7916793326d23b465222a407.png) [@system](https://community.mp3tag.de/u/system)\
**Post date:** [February 9, 2026, 12:26pm UTC](https://community.mp3tag.de/t/how-to-escape-ampersands-in-xml-export/18870/8 "2026-02-09T12:26:46Z")

</div>


