XML export reserved characters


#1

I'm a complete newbie with very limited coding experience...with a simple problem. So I appreciate any and all patience and help.

Here is my problem: When I export into an xml, reserved characters are showing up funny.
Example(s): "For his about-to-be-released autobiography, �My Life�" & "I don�t see it as a problem"

First question: What code do I need to cancel out reserved characters?
Second question: Where do I put this code?

Again, thank you for helping a guy who feels like a complete idiot for not figuring this out for himself.

Best,
Kumba


#2

Please.....can someone give me a quick answer to this?


#3
  1. How do you create the xml file?
  2. Give us an impression of your "Mp3tag export to xml" script file.
  3. Show us the first script line of the Mp3tag xml export script.
  4. Using what application do you see the crippled output characters?
  5. Read the manual about character encoding option when using $filename().
  6. Set the character encoding for the xml data, e. g.
<?xml version="1.0" encoding="ISO-8859-1"?>
  1. Hide illegal characters from the XML parser by using the term CDATA, e. g.
    ''

DD.20100816.0432.CEST


#4

Thank you so much for your help on this, it is GREATLY appreciated. I will try and answer these to the best of my limited ability and please feel free to ask more questions in detail if need be.

  1. Create xml = I made a (not so good) template via mp3tag
    2/3/6. Script =
<?xml version="1.0" encoding="utf-8"?> $loop(%songpath%) $loopend()
  1. I use FLASH to parse the xml into a datagrid and it works fine except for the reserved chcaracters.
  2. I will look in the manual after this email, thanks for the heads-up
  3. I will try the CDATA insertion as soon as possible.

Again, thanks and I hope what I've provided gives you some insight.

Best,
Kumba


#5

This export script creates a xml file which will be displayed correctly in XML Notepad.

$filename(O:\TEST\Test1.xml,utf-8)'<?xml version="1.0" encoding="utf-8"?>'
'<songs>'
$loop(%_path%)
'<song>'
'<![CDATA[path="'$replace(%_path%,'\','/')'"]]>'
'<![CDATA[title="'%title%'"]]>'
'<![CDATA[artistname="'%artist%'"]]>'
'<![CDATA[time="'%_length%'"]]>'
'<![CDATA[source="'%comment%'"]]>'
'<![CDATA[verbatim="'%album%'"]]>'
'<![CDATA[topic="'%subtitle%'"]]>'
'<![CDATA[notes="'%band%'"]]>'
'</song>'
$loopend()
'</songs>'

If this is not the right way to go ... and you want to escape characters like "<", ">", "&" and so on, then you need somewhat of a html encoding function to encode e. g. "<" to "<".
You can build your own html encoder by using Mp3tag function $replace.
Example:

$replace(%comment%,'<','&_lt;','>','&_gt;','&','&_amp;','[','&_#91;',']','&_#93;','"','&_#34;')

To fake the forum posting renderer I had to use the surrogate character sequence "&_" instead of simple "&", so remove the underline characters from the above code line when using it in reality.
Same for the following export script.

$filename(O:\TEST\Test2.xml,utf-8)'<?xml version="1.0" encoding="utf-8"?>'
'<more_songs>'
$loop(%_path%)
'<song'
'path="'$replace($replace(%_path%,'<','&_lt;','>','&_gt;','&_','&_amp;','[','&_#91;',']','&_#93;','"','&_#34;'),'\','/')'"'
'title="'$replace(%title%,'<','&_lt;','>','&_gt;','&_','&_amp;','[','&_#91;',']','&_#93;','"','&_#34;')'"'
'artistname="'$replace(%artist%,'<','&_lt;','>','&_gt;','&_','&_amp;','[','&_#91;',']','&_#93;','"','&_#34;')'"'
'time="'$replace(%_length%,'<','&_lt;','>','&_gt;','&_','&_amp;','[','&_#91;',']','&_#93;','"','&_#34;')'"'
'source="'$replace(%comment%,'<','&_lt;','>','&_gt;','&_','&_amp;','[','&_#91;',']','&_#93;','"','&_#34;')'"'
'verbatim="'$replace(%album%,'<','&_lt;','>','&_gt;','&_','&_amp;','[','&_#91;',']','&_#93;','"','&_#34;')'"'
'topic="'$replace(%subtitle%,'<','&_lt;','>','&_gt;','&_','&_amp;','[','&_#91;',']','&_#93;','"','&_#34;')'"'
'notes="'$replace(%band%,'<','&_lt;','>','&_gt;','&_','&_amp;','[','&_#91;',']','&_#93;','"','&_#34;')'"'
'/>'
$loopend()
'</more_songs>'

The last export script will give oiutput like the following lines ...

<?xml version="1.0" encoding="utf-8"?>
<more_songs>
  <song path="O:/TEST/T1/Divers ~ 00 ~ Genre ~ Electronic - Minimal-Tech House/02.mp3" title="I'm an Old Cowhand from the Rio Grande" artistname="Old Cowhand" time="00:00" source="&quot;For his about-to-be-released autobiography 'My Life'&quot; &amp; &quot;I don't see it as a problem&quot;. " verbatim="Rio Grande" topic="" notes="" />
</more_songs>

DD.20100820.1919.CEST


#6

Hi again DetlevD,

Thank you so much for all your help. I ended up using the 2nd script you wrote (longhand) and it worked for what I needed. I was trying to import xml CDATA into PHP and it got 'angry' with any approach I did.

I did have another quick question. Is there a way to change the default field names in the tag panel? I know I can add more fields if needed but I wanted to check if I can change the originals in a .ini file or something.

Again, thank you so much for your time!

Best,
Kumba


#7

I am glad to hear this.

I know nothing about it.

DD.20100909.1922.CEST


#8

.