Output of formatted text from the database or XML

Source: Internet
Author: User

When outputting text, replace spaces, carriage return, and other characters with HTML tags. Here I read the text from the XML document. The text itself is stored in a formatted format: the XML structure is as follows:

 

<? XML version = "1.0" encoding = "UTF-8"?>
<Jgxy>
<News>
<News_title> News Title </news_title>
<News_author> News author </news_author>
<News_date> date </news_date>
<News_source> source </news_source>
<News_content> news content ...... </News_content>
</News>

In. CSCode:

 

protected void page_load (Object sender, eventargs e)
{< br> string url = server. mappath ("~ /App_data/news. XML "); // open the XML document
xmldocument Doc = new xmldocument (); // create a DOM document
Doc. load (URL);
xmlnodelist nodelist = Doc. getelementsbytagname ("news_content"); // obtain the "news_content" node set
xmlnode node = nodelist. item (0); // I display the news content of the first node
string text = node. firstchild. value;
response. write (this. myreplace (text);

}< br> Public String myreplace (string mystr) // character replacement function
{< br> If (mystr + "A" = "") // determine whether it is a space
{< br> return ("& nbsp;");

}< br> else // press ENTER
{< br> mystr = mystr. replace ("\ n \ r", "
");
mystr = mystr. replace ("\ r", "
");
mystr = mystr. replace ("\ t", "");
return (mystr);

}< BR >}

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.