Search code examples
androidasp.netweb-servicesxml-parsingashx

How can I apply CDATA in XML for webservices in asp.net?


How can I apply CDATA here in such XML of web services in asp.net, as in

<booktitle> data </booktitle>

I have some symbols like '&', which resist me to parse it to Android.

Here is my code:

for (int iBookResponse = 0; iBookResponse < dataTable.Rows.Count; iBookResponse++)
                {
                    DataRow dataRow = dataTable.Rows[iBookResponse];

                    xmlResponse += "<Book>";
                    xmlResponse += "<BookID>" + dataRow["book_id"].ToString() + "</BookID>";
                    xmlResponse += "<BookCode>" + dataRow["book_code"].ToString() + "</BookCode>";
                    xmlResponse += "<BookTitle>" + dataRow["book_title"].ToString()+ "</BookTitle>";
                   xmlResponse += "</Book>";

        }

Solution

  • Just prepend xmlResponse with <![CDATA[ and append ]]> to it. So your xmlResponse can start with

    xmlResponse += "<![CDATA[<Book>";
    

    and end it with

      xmlResponse += "</Book>]]>"
    

    with everything else in between.