0

I am using simpleXml to parse my xml but it always breaks the page when i try to parse Spanish, french, Estonian, Portuguese, superscripts or subscripts.

Any Idea ??

Example of the XML :-

<carddata> <logo_id>0</logo_id> <cscale>Ñ</cscale><carddata>

Scripts :-

$carddetail = new SimpleXMLElement($xml);
$carddetail = iconv('UTF-8', 'ISO-8859-15//TRANSLIT', $carddetail);

In the xml i sent

<cscale><![CDATA[Peter Nortoné]]></cscale> 

and the error is:

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: Entity: line 22: parser error : CData section not finished Peter Nort in D:\xampp\htdocs\logosnap\card.php on line 144

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: <text><\![CDATA[Peter Norton in D:\xampp\htdocs\logosnap\card.php on line 144
Giacomo1968
  • 25,759
  • 11
  • 71
  • 103
Shaun
  • 2,313
  • 7
  • 36
  • 43
  • ` 0 Ñ` – Shaun Dec 09 '11 at 07:42
  • PHP Code: `$carddetail = new SimpleXMLElement($xml); $carddetail = iconv('UTF-8', 'ISO-8859-15//TRANSLIT', $carddetail);` – Shaun Dec 09 '11 at 07:43
  • turn out you have use the iconv wrongly, can you double check what is the charset for the XML string? If is already is UTF-8,why bother to convert to ISO? – ajreal Dec 10 '11 at 04:00

1 Answers1

1
$carddetail = new SimpleXMLElement($xml);  
<-- this set $carddetail as simplexmlelement object

You can't use the object as string like :-

$carddetail = iconv('UTF-8', 'ISO-8859-15//TRANSLIT', $carddetail);

So, try this :-

$carddetail = new SimpleXMLElement(iconv('UTF-8','ISO-8859-15//TRANSLIT',$xml));
ajreal
  • 46,720
  • 11
  • 89
  • 119
  • In the xml i sent `<![CDATA[Peter Nortoné]]>` and the error is `Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: Entity: line 22: parser error : CData section not finished Peter Nort in D:\xampp\htdocs\logosnap\card.php on line 144 Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: <![CDATA[Peter Norton in D:\xampp\htdocs\logosnap\card.php on line 144` – Shaun Dec 09 '11 at 09:59