Bug or working as intended with PEAR XMLParser ?
| From: | Anthony Limana | Date: | Thu, 19 Feb 2009 10:44:53 +0000 |
| Subject: | Bug or working as intended with PEAR XMLParser ? | ||
| Groups: | php.pear.general | ||
| Request: | Send a blank email to pear-general+get-29708@lists.php.net to get a copy of this message | ||
Hello,
I'm a professionnal Java Programmer and I recently had to learn PHP for the need of a contract.
I needed to parse an XML message and discovered PEAR.
Here is my problem:
- I decided to use the XMLParser in func mode and managed to parse my entire document without any issue until I realized that I had a weird bug when parsing CDATA that contains non-english characters (I'm talking about accents here "é", "è" etc.)
Here is a bit of my code and of the xml im trying to parse (i've cut the irrelevant parts);
function cdataHandler($parser, $data) {
global $isEmailContext;
$data = trim($data);
if (empty ($data)) {
return true;
}
if ($isEmailContext == true) {
echo "Email: " . $data . "<br>";
$currentReservation->resGlobalInfo->email = $data;
}
}
as you can see when I'm in the right context (when isEmailContext is true) the CDATA I parse should display something like that:
Email: suppéort@hotel.com
given my XML is :
<Email><suppéort@hotel.com></Email>
In fact it works with every single CDATA there is in the document BUT the ones where there are accents (i didn't test with other special characters). Instead it displays this very weird thing:
Email: supp
Email: éort@hotel.com
It seems that the parser interprets the accent as an escape character or something like that and make the parser do a second call to the cdataHandler function.
By changing my XML to:
<Email><![CDATA[suppéort@hotel.com]]></Email>
I manage to fix this behaviour but unfortunately in the real application I won't have the possibility to change the XML, therefore it has to work without that.
I'm new to PHP so the solution might be actually easy, but in the API documentation and even in the API source code I've found nothing that could help me work around this issue.
Contact me if you have any questions.
Thank you.
--
Teracom
*Anthony LIMANA**
Ingénieur Logiciel*
Sun Java Programmer Certified
*Teracom * Le Palatin, Centre Europe - 83400 Hyères - FRANCE
*TELEPHONE* +33 (0)4 94 12 72 00
*Fax :* +33 (0)4 94 35 40 29
TERACOM - Ingénierie Logicielle . Sécurité . Intégration
www.teracom.fr <http://www.teracom.fr>