I am running into a problem parsing the following XML file:
<?xml version="1.0" encoding="utf-8"?>
<map state="Arizona" background="ffffff" textColor="000000" normal="ffff99" rollover="ff9900" border="333333" rollover_sound="true">
<county normal="" rollover="" name="Mohave" url="listings.php?state=arizona&county=Mohave"/>
</map>
The error is caused by the url attribute having "?state=arizona&county=Mohave". The XML code below works fine:
<?xml version="1.0" encoding="utf-8"?>
<map state="Arizona" background="ffffff" textColor="000000" normal="ffff99" rollover="ff9900" border="333333" rollover_sound="true">
<county normal="" rollover="" name="Mohave" url="listings.php"/>
</map>
Has anyone had this problem before and is there a fix?
Thanks for a great script!!!
Neal St. Clair
idesignbusiness.com
I did a bit more troubleshooting and found a fix. I changed the XML to this and it works:
<?xml version="1.0" encoding="utf-8"?>
<map state="Arizona" background="ffffff" textColor="000000" normal="ffff99" rollover="ff9900" border="333333" rollover_sound="true">
<county normal="" rollover="" name="Mohave" url="listings.php?state=arizona?county=Mohave"/>
</map>
What worked was changing the &county= to ?county=
Hopefully this helps someone else out.
Neal St. Clair
idesignbusiness
Hi Neal,
I think we cross-posted! You can still use the & - see my post above for how to correctly encode it within the XML...
Cheers,
David.
I changed the & symbol to & and it worked like a charm. Thanks again for a great product and amazing support!!!
Neal
Hello Neal,
Thank you for your comments!
If the first block of code you posted is exactly what is returned to you, the problem is that the & character is not entity encoded, so it is not valid XML. Any XML parser, when encountering the & character goes into entity decoding mode, and as, in this case, it is not followed by an entity the parsing has to stop because it is not known how to continue.
Wherever the & character appears within an XML document, it must be specified as:
&
Therefore, the first sample of XML, with this corrected, would be as follows:
<?xml version="1.0" encoding="utf-8"?>
<map state="Arizona" background="ffffff" textColor="000000" normal="ffff99" rollover="ff9900" border="333333" rollover_sound="true">
<county normal="" rollover="" name="Mohave" url="listings.php?state=arizona&county=Mohave"/>
</map>
(I just pasted this into the demo tool and it works fine)
However, if you are not in control of the generation of this XML, then you have to deal with it some how. The easiest thing to do, provided that the source if relatively small (as in these samples) is to str_replace() the & for the correct entity. To do this in your code, you could use something like (assuming the XML is loaded into $xml):
<?php
$xml = str_replace("&","&",$xml);
MagicParser_parse("string://".$xml,"myRecordHandler","xml|FORMAT/STRING/");
?>
Let me know if you need any more help dealing with this!
Regards,
David.