amp in xml getting comverted to “&”

I am creating one url and adding & to that url.

eg http://xyzc.com/abc.php?arg1=value1&arg2=value2

Now I am adding this url to xml .

I am creating xml via tinyxml in c++ and also tried creating same xml in php.

After creating the xml I found out that "&" is converted to "&"

Is it okay for "&" to get converted to "&"? Why is this happening ? And what could be the possible fix for this?

$strUrl ="http://xyzc.com/abc.php?";
$strUrl .="arg1=".$value1;
$strUrl .="&arg2=".$value2;

The output is coming as

http://xyzc.com/abc.php?arg1=10&arg2=100

Answers


XML has a feature called a character reference (&thingy;)

Therefore, all raw & characters must be escaped as & This is a pre-defined character reference equivalent to & (amp stands for ampersand).

Leaving an unescaped & will create invalid XML.

Note that raw < characters must also be escaped as &lt; (lt stands for less-than).


Need Your Help


About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.