How to escape ampersands in XML export

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!

You could change the generating line to

Indeed, this has worked. Thank you very much!

But how do you escape multiple?

$replace(%artist%,'&','&') works fine, but as I red from documentation, 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.

You can test your expression in Convert>Tag-Tag.
This one should be
To show code as code, enclose it in accent-grave.

1 Like

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

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

You only need to “escape”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.

1 Like