I have written a piece of similarArticleHe was instructed by R2. he found that there was a problem in it, so he reorganized it and debugged it. There were a lot of similar online content, but he just wanted to sort it out, you don't need to try again later.
1. announcement board (News list)
Newslist. xml
<? XML version = "1.0" encoding = "gb2312"?>
<Topiclist type = "aspcool News">
<Topic>
<Title> first news </title>
<Href> main. aspx? Name = news1
</Topic>
<Topic>
<Title> second news </title>
<Href> main. aspx? Name = new2
</Topic>
</Topiclist>
Shownewslist. aspx
<% @ import namespace =" system "%>
<% @ page Language =" C # "DEBUG =" true "codePage =" 936 "%>
<% @ import namespace =" system. io "%>
<% @ Assembly name =" system. XML "%>
<% @ import namespace =" system. XML "%>
<% @ import namespace =" system. XML. XSL "%>
<% = XSLT () %>
2. The display of each piece of news is the same.
3. How to Create a news item
News1.xml
<? XML version = "1.0" encoding = "gb2312"?>
<Document>
<Title> aspcool news! </Title>
<ABSTRACT> test news </abstract>
<Author> feiying </author>
<Content>
<Paragraph> the firet test </Paragraph>
</Content>
</Document>
News1.xml Method
Private void btngetxml_click (Object sender, system. eventargs E)
{
Stirng filename=this.txt filename. test;
String titlepolicthis.txt title. text;
String abstract=this.txt abstract. text;
String Authorizer this.txt author. text;
String content+this.txt content. text;
// Determine whether a file exists
If (file. exists (server. mappath (filename + ". xml ")))
{
Response. Write ("the file name already exists. Please reselect the file name. ");
Response. End ();
}
Else
{
// Create news1.xml
System. xml. xmltextwriter mywriter = new xmltextwriter (filename + ". xml", null );
Mywriter. writeprocessinginstruction ("XML", "version = '1. 0 '");
Mywriter. writestartelement ("content ");
Mywriter. writeattributestring ("type", "whitepaper ");
//
Mywriter. writestartelement ("document ");
Mywriter. writeelementstring ("title", title );
Mywriter. writeelementstring ("abstract", abstract );
Mywriter. writeelementstring ("author", author );
Mywriter. writeelementstring ("content", content );
//
Mywriter. writeendelement ();
Mywriter. Flush ();
Mywriter. Close ();
}
}
4. How to modify the existing newslist. xml
Each time a piece of news is added, add the previous one to newslist. xml.
Private void updatenewslist (String title, string href)
{
// Add new nodes to newslist. xml
Xmldocument mydocument = new xmldocument ();
Mydocument. Load ("newslist. xml ");
Xmlelement topiclist = (xmlelement) mydocument. getelementsbytagname ("topiclist ");
Xmlelement topic = mydocument. createelement ("topic ");
Xmlelement Title = topic. createelement ("title ");
Title. innertext = title;
Topic. appendchild (title );
Xmlelement href = topic. createelement ("href ");
Href. innertext = href;
Topic. appendchild (href );
Topiclist. prependchild (topic );
Mydocument. Save ("newslist. xml ");
}