I have created a string
<?xml version='1.0' encoding='ISO-8859-1'?>
<response>
<content>Question - aa.Reply the option corresponding to your answer(You can vote only once)</content>
<options>
<option url="http://localhost/poll/index.php?message=vote%3Aaar1%3Asdy&mobile=9747444565" name="sdy"/>
<option url="http://localhost/poll/index.php?message=vote%3Aaar1%3Ab&mobile=9747444565" name="b"/>
</options>
</response>
The url attribute of the option tag is created from the following php code
$appUrl."/poll/index.php?message=".urlencode("vote:".$kwd.":".$oopt)."&mobile=".urlencode($_GET['mobile']);
But when I convert the same to xml ,I am getting the following error.
This page contains the following errors:
error on line 1 at column 240: EntityRef: expecting ‘;’
Below is a rendering of the page up to the first error.
Why is this happening.I am sure that it is problem of url encoding.So what is the correct way of url encoding.I mean
what changes should be applied to the url encoding
$appUrl."/poll/index.php?message=".urlencode("vote:".$kwd.":".$oopt)."&mobile=".urlencode($_GET['mobile']);
Get parameters and value of them are
$_GET['message'] = "vote:".$kwd.":".$oopt
$_GET['mobile'] = 888888errt434
You have an un-encoded
&(ampersand) character in the URLs.&is a special character in all SGML-based forms of markup.htmlspecialchars()will fix the problem:Personally I prefer to use DOM for creating XML documents instead of string concatenation. This will also handle encoding of SGML special characters correctly. I would do something like this:
Working example