日期:2014-05-20 浏览次数:20951 次
<%
on error resume next
Dim SQL,RS
Set RS = Server.CreateObject("ADODB.RecordSet")
Set conn = server.createobject("adodb.connection")
OpenDBConn conn
SQL = "SELECT f1,f2,f3 FROM table1 WHERE f1=xx"
RS.Open SQL,Conn,1,1
RS.MoveFirst
Dim xmldoc
Set xmldoc = server.CreateObject("Msxml2.domdocument")
Dim version
Set version = xmldoc.createProcessingInstruction("xml","version='1.0' encoding='GB2312'")
xmldoc.appendchild(version)
Dim root
Set root = xmldoc.createElement("root")
xmldoc.appendChild(root)
while Not RS.EOF
Set childNode = xmldoc.createElement("node1")
For Each f in rs.Fields
Set childnextNode = xmldoc.createElement(f.name)
childnextNode.Text = f.Value
childNode.appendChild(childnextNode)
Next
RS.MoveNext
root.appendChild childNode
wend
xmldoc.save(Server.Mappath("info.xml"))
%>
------解决方案--------------------
XmlDocument xmlDoc = new XmlDocument();
//生成描述版本
XmlDeclaration xmlDec;
xmlDec = xmlDoc.CreateXmlDeclaration("1.0", "gb2312", "yes");
xmlDoc.InsertBefore(xmlDec, xmlDoc.DocumentElement);
//定义根节点
XmlElement element;
XmlNode rootNode;
XmlNode subNode;
element = xmlDoc.CreateElement("message");
element.SetAttribute("System", "ATMS");
element.SetAttribute("Ver", "1.0");
rootNode = xmlDoc.AppendChild(element);
//定义子系统
element = xmlDoc.CreateElement("systemtype");
element.InnerText = SubType;
rootNode.AppendChild(element);
//定义消息类型
element = xmlDoc.CreateElement("messagetype");
element.InnerText = "ALARM";
rootNode.AppendChild(element);
//定义子系统
element = xmlDoc.CreateElement("systemtype");
element.InnerText = SubType;
rootNode.AppendChild(element);
//发出消息的源ip地址
element = xmlDoc.CreateElement("sourceIP");
element.InnerText = "";
rootNode.AppendChild(element);
//接收消息的目的ip地址
element = xmlDoc.CreateElement("sourceIP");
element.InnerText = "";
rootNode.AppendChild(element);
//用户名
element = xmlDoc.CreateElement("user");
element.InnerText = "";
rootNode.AppendChild(element);
//密码
element = xmlDoc.CreateElement("password");
element.InnerText = "";
rootNode.AppendChild(element);
element = xmlDoc.CreateElement("Alarm");
element.InnerText = "";
rootNode.AppendChild(element);
element = xmlDoc.CreateElement("type");
element.InnerText = "";
rootNode.LastChild.AppendChild(element);
element = xmlDoc.CreateElement("device");
element.InnerText = "";
subNode=rootNode.LastChild.AppendChild(element);
element = xmlDoc.CreateElement("id");