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 >}