1. XML style
2 <root>
3 <cast>
4 <senduserid> 3 </senduserid>
5 <title> asdafdf </title>
6 <content> sadggdfaf </content>
7 <datetime> 18:11:23 </datetime>
8 <listuser>
9 <acceptuserid> 42 </acceptuserid>
10 <acceptuserid> 43 </acceptuserid>
11 </listuser>
12 </cast>
13 </root>
14
15 C # code
16 /// <summary>
17 // create an XML file
18 /// </Summary>
19 /// <Param name = "userid"> recipient's ID </param>
20 /// <Param name = "title"> title </param>
21 /// <Param name = "content"> content </param>
22 public static void createxml (string userid, String title, string content)
23 {
24 xmldocument xmldoc = new xmldocument ();
25 xmlnode = xmldoc. createxmldeclaration ("1.0", "UTF-8", null );
26 xmldoc. appendchild (xmlnode );
27 // create the root node
28 xmlelement xmlroot = xmldoc. createelement ("root ");
29
30
31 // create a level-1 Node
32 xmlelement xmlcast = xmldoc. createelement ("cast ");
33 xmlroot. appendchild (xmlcast );
34 // create a secondary node and its parallel nodes
35 xmlelement xmlsend = xmldoc. createelement ("senduserid ");
36 xmlsend. innertext = wangcaiconfig. User. Id. tostring ();
37 xmlcast. appendchild (xmlsend );
38
39 xmlelement xmlsubject = xmldoc. createelement ("title ");
40 xmlsubject. innertext = title;
41 xmlcast. appendchild (xmlsubject );
42
43 xmlelement xmlcontent = xmldoc. createelement ("content ");
44 xmlcontent. innertext = content;
45 xmlcast. appendchild (xmlcontent );
46
47 xmlelement xmltime = xmldoc. createelement ("datetime ");
48 xmltime. innertext = datetime. Now. tostring ();
49 xmlcast. appendchild (xmltime );
50
51 // create a level-3 Node
52 xmlelement xmllist = xmldoc. createelement ("listuser ");
53 xmlcast. appendchild (xmllist );
54
55 string [] useridlist = userid. Split ('&');
56 for (INT I = 0; I <useridlist. Length-1; I ++)
57 {
58 // create level-4 nodes and their parallel nodes
59 xmlelement xmlacceptid = xmldoc. createelement ("acceptuserid ");
60 xmlacceptid. innertext = useridlist [I]. tostring ();
61 xmllist. appendchild (xmlacceptid );
62}
63 // bind the root node
64 xmldoc. appendchild (xmlroot );
65 xmldoc. Save (wangcaiconfig. getcurrentdirectory () + "userxml/boradcast. xml"); view codeview code
Create XML add data to XML