asp.net implementation Write a CDATA method in XmlTextWriter-practical tips

Source: Internet
Author: User
Tags cdata html tags

The example in this article tells the asp.net implementation to write a CDATA method in XmlTextWriter. Share to everyone for your reference, specific as follows:

CDATA can be used to write HTML tags like <br>,<script> or any other markup. You cannot add a simple write writeelementstring to these tags. Converts the character < to >. The following example shows the use of writeelementstring to write a CDATA region.

Add a reference first

Using System.Xml

In a program like this to write

void Page_Load (object sender, System.EventArgs e) {
  XmlTextWriter xmlWriter = new XmlTextWriter (Server.MapPath (" Xmltextwriterwithwritecdata.xml "), null);
  Automatic formatting of xml
  xmlwriter.formatting = formatting.indented;
  Writes the root element
  xmlwriter.writestartelement ("CategoryList");
  Writes the first element
  xmlwriter.writestartelement ("Category");
  Adding elements to the category element
  xmlwriter.writeelementstring ("Maincategory", "<br>");
  Write CDATA
  xmlwriter.writecdata ("<br>");
  Write End character
  xmlwriter.writeendelement ();
  Close writer
  xmlwriter.close ();
  Response.Write ("Xml written");


More interested readers of asp.net related content can view the site topics: "asp.net operation XML Skills summary", "asp.net file Operation skills Summary", "ASP.net Ajax Skills Summary topic" and "asp.net cache operation skills Summary."

I hope this article will help you to ASP.net program design.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.