The following file works on the demo page; however, it only outputs the first record when I use the script. It seems like Magic Parser will stop if it encounters a character it does not like such as º or °. Notice the ° after purrs in the second record. I did not get an error message from MagicParser_getErrorMessage().
Could you explain why it would work on the demo page and not when I run it on my system?
<?xml version="1.0" encoding="utf-8"?>
<pets>
<pet name="Bonzo">
<type>Dog</type>
<KeyFeatures>
<Key>
<MainSpec>Color</MainSpec>
<Formcontent><![CDATA[Brown]]></Formcontent>
</Key>
<Key>
<MainSpec>Distinguishing Sound</MainSpec>
<Formcontent><![CDATA[Barks]]></Formcontent>
</Key>
</KeyFeatures>
</pet>
<pet name="Flufy">
<type>Cat</type>
<KeyFeatures>
<Key>
<MainSpec>Color</MainSpec>
<Formcontent><![CDATA[Black]]></Formcontent>
</Key>
<Key>
<MainSpec>Distinguishing Sound</MainSpec>
<Formcontent><![CDATA[Purrs°]]></Formcontent>
</Key>
</KeyFeatures>
</pet>
</pets>
Your files worked.
My format string was the same as yours.
However, my original xml file was saved as ANSI. I resaved it in notepad as UTF-8 and it worked!
Problem solved!
I spent 3 hours trying to figure this out. You are amazing! Thanks for the help.
Hi,
This sounds like it could be a character encoding mis-match between the utf-8 declaration in the XML; and the actual encoding of the file (which may-be iso-8859-1).
Also make sure that you are using a Format String in your call to MagicParser_parse(), which in this case should be:
xml|PETS/PET/
To help you work out whether or not it is an encoding issue; I have created the following demo script with the XML in your post saved in a file called pets.xml:
http://www.magicparser.com/examples/pets.php
Click here to download both files (pets.php and pets.xml) as a .zip. If this works on your server, the first thing to check is that the text editor in which you are creating the file is configured to be using the utf-8 character set as matches the character set in the declaration - and I expect that will be all it is...
Cheers,
David.