RSS

[xml][error][solution]Fix for “XML Parsing Error: not well-formed”

25 Oct

For resolving XML Parsing Error: not well-formed use any of following:
1) XML CDATA as the term CDATA is used about text data that should not be parsed by the XML parser.Enclose the code in between <![CDATA[ and ]]>

e.g.

 "<![CDATA[<".$key.">".$value."</".$key.">]]>"

2) htmlspecialchars

e.g.

"<".htmlspecialchars($key).">".htmlspecialchars($value).
"</".htmlspecialchars($key).">"

3) Customized special character handling function

e.g.

"<".$key.">".xmlentities($value)."</".$key.">"
function xmlentities($text)
{
$search = array('&','<','>','"','\'');
$replace = array('&amp;','&lt;','&gt;','&quot;','&apos;');
$text = str_replace($search,$replace,$text);
return $text;
}
Advertisements
 
Leave a comment

Posted by on October 25, 2011 in xml parsing

 

Tags: , , ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: