相关源代码FORXML
1
using System;
2
using System.Xml;
3
using System.Collections;
4
using System.ComponentModel;
5
using System.Data;
6
using System.Data.OleDb;
7
using System.Data.Common;
8
using System.Drawing;
9
using System.Web;
10
using System.Web.SessionState;
11
using System.Web.UI;
12
using System.Web.UI.WebControls;
13
using System.Web.UI.HtmlControls;
14
15
namespace Dtxml
16
{
17
/// <summary>
18
/// function is transform XML from a file to another file.
19
/// copyright by Mcdule(wangzl)。
20
/// </summary>
21
public class WebForm2 : System.Web.UI.Page
22
{
23
24
protected System.Web.UI.HtmlControls.HtmlGenericControl outResult2;
25
protected System.Web.UI.HtmlControls.HtmlGenericControl outMessage;
26
27
private void Page_Load(object sender, System.EventArgs e)
28
{
29
30
string strConnect = System.Configuration.ConfigurationSettings.AppSettings["DsnWroxBooksOleDb"];
31
string strCurrentPath = Request.PhysicalPath;
32
string strXMLPath = strCurrentPath.Substring(0, strCurrentPath.LastIndexOf("\\")) + "\\booksource.xml";
33
string strnewPath = strCurrentPath.Substring(0, strCurrentPath.LastIndexOf("\\")) + "\\rssxml.xml";
34
string strSelect = "SELECT BookList.*, BookAuthors.FirstName, BookAuthors.LastName "
35
+ "FROM BookList INNER JOIN BookAuthors ON BookList.ISBN = BookAuthors.ISBN "
36
+ "WHERE BookList.ISBN LIKE '0764544%'";
37
38
39
40
// 在此处放置用户代码以初始化页面
41
42
DataSet objDataSet = new DataSet();
43
44
try
45
{
46
// create a new OleDbConnection object using the connection string
47
OleDbConnection objConnect = new OleDbConnection(strConnect);
48
49
// create a new OleDbDataAdapter using the connection object and select statement
50
OleDbDataAdapter objDataAdapter = new OleDbDataAdapter(strSelect, objConnect);
51
52
// fill the dataset with data from the DataSetCommand object
53
objDataAdapter.Fill(objDataSet, "item");
54
}
55
catch (Exception objError)
56
{
57
// display error details
58
outMessage.InnerHtml = "<b>* Error while accessing data</b>.<br />"
59
+ objError.Message + "<br />" + objError.Source;
60
return; // and stop execution
61
}
62
objDataSet.WriteXml(strXMLPath);
63
// create new empty XML Document object
64
XmlDocument objnewDoc = new XmlDocument();
65
XmlDocument objXMLDoc = new XmlDocument();
66
objXMLDoc.Load(strXMLPath);
67
68
string strXpath="descendant::NewDataSet";
69
XmlNode objNode;
70
objNode=objXMLDoc.SelectSingleNode(strXpath);
71
72
73
objnewDoc.AppendChild(objXMLroot);
74
// ********************创建根节点RSS,并赋属性值************
75
string xmlstr="<rss version='2.0'>"+"</rss>";
76
77
78
objnewDoc.LoadXml(xmlstr);
79
XmlNode root=objnewDoc.DocumentElement;
80
//**************创建所需的子节点,并赋值*****************
81
82
XmlElement elem=objnewDoc.CreateElement("Channel");
83
84
root.InsertAfter(elem,root.FirstChild);
85
86
XmlElement elemtitle=objnewDoc.CreateElement("title");
87
elemtitle.InnerText="某某集团内网最新资讯";
88
89
XmlElement elemlink=objnewDoc.CreateElement("link");
90
elemlink.InnerText=http://*.*.com;
91
92
XmlElement elemdes=objnewDoc.CreateElement("description");
93
elemdes.InnerText="网站发布的最新文章、栏目和资源信息";
94
95
XmlElement elemlan=objnewDoc.CreateElement("language");
96
elemlan.InnerText="zh-cn";
97
98
99
string strSPath="descendant::Channel";
100
101
XmlNode SelNode=objnewDoc.SelectSingleNode(strSPath);
102
SelNode.AppendChild(elemtitle);
103
SelNode.AppendChild(elemlink);
104
SelNode.AppendChild(elemdes);
105
SelNode.AppendChild(elemlan);
106
107
108
// ************从源文件中选择所需的节点导入目的文件中指定的位置***********
109
string strLPath = "descendant::item";
110
XmlNodeList colNodeList;
111
colNodeList = objXMLDoc.SelectNodes(strLPath);
112
113
foreach (XmlNode objNd in colNodeList)
114
{
115
116
XmlNode objImDode=objnewDoc.ImportNode(objNd, true);
117
// objnewDoc.DocumentElement.InsertAfter(objImDode,SelNode);
118
SelNode.AppendChild(objImDode);
119
120
}
121
122
123
124
objnewDoc.Save (strnewPath);
125
126
}
127
128
Web 窗体设计器生成的代码
147
}
148
}
149

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

147

148

149
