简体   繁体   中英

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>";

        }

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM