I'm using simplexml_load_file for handling a third party xml.... this usually works fine, but sometimes, for a reason i'm unable to discover, i'm getting some warnings and the script can't handle the data...
WARNINGS:

Warning: simplexml_load_file(): input conversion failed due to input error, bytes 0x9A 0x6B 0x6F 0x76
Warning: simplexml_load_file(): encoder error
parser error : Premature end of data in tag match

PART OF XML CODE

<?xml version="1.0" encoding="windows-1253"?>
<coupon couponTitle="23/7/2009">
<description>whatever</description>
<match  date="23/7/2009" time="01:30" homeTeam="Flamengo RJ" awayTeam="Barueri SP" championShip="Brazil - Serie A Brasileiro">
<status>4</status>
<score>1-1</score>
<halftime>0-0</halftime>
<min>FIN</MIN>
<info>"(goal) Baiano (pen) 53' | (goal) Emerson 69' | "</info>
<goalnow>""</goalnow>
<result>"X"</result>
......
</match>

XML is using windows-1253, and probably that's the problem (just a guess), however this only happens a few times. Most of the time there's no problem. What could be the problem?

    I would suspect somewhere in your tags there's a stray "/" somewhere and it's not escaped, or you're sending some html tag or something. I would try changing the xml to have everything that is sending a string (like info, goalnow, result) wrapped in CDATA tags so the xml parser knows not to interpret that. E.g.

    <info><![CDATA["(goal) Baiano (pen) 53' | (goal) Emerson 69' | "]]></info>

    Then, I would ask why you're splitting data in php (just a guess) instead of just utilizing xml to its fullest. E.g.

    <info>
        <goal player="Baiano" distance="53'" />
        <goal player="Emerson" distance="69'" />
    </info>

    Hope that helps.

      Unforunatelly i can't change the xml structure as it is a data feed i'm getting from someone else. I got a copy of a version of the xml that produced that error (as i mentioned most of the time the xml is fine) which has some weird spaces, all in info tags. I tried adding CDATA but still the same thing. Opening the xml with dreamweaver, shows the text in info tags correctly, but when opening it in a browser, i can see some spaces that shouldn't be there. I've noticed that as a player's name has been split in two, and then i saw all entries that produce error having an extra space (before or after a regular space). Maybe some weird characters are there that i can't see with dreamweaver?

        if there are missing closing tags, as with the sample us demo, and this occurs on a regular basis, and if u really need this feed, u can do 1 of 2 things:-
        1. feed the xml to a file on your own site, usually, since these feeds are structured programatically, you will find the error at the same place holder in the code, therefore u cld fix it yourself.
        2. Contact the feed owner, I'm sure they wld like to know about it, they will fix it.

          There are no missin tags in the xml, i just copied here code from the beginning of the xml to the first match entry.

          You mean i should use the file() function and save it on my server? The problem doesn't have to do with the xml encoding?

            no use file_get_contents($file);
            read the xml with dom to find the error, and if u dont know how to do this, use a validator!

              Write a Reply...