XmlDocument,XmlNode,XmlElement创建复杂XML文档
#region 生成XML消息
XmlDocument xmlDoc = new XmlDocument();
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
//生成描述版本
XmlDeclaration xmlDec;
xmlDec = xmlDoc.CreateXmlDeclaration("1.0", "gb2312", "yes");
xmlDoc.InsertBefore(xmlDec, xmlDoc.DocumentElement);
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
//定义根节点
XmlElement element;
XmlNode rootNode;
XmlNode subNode;
element = xmlDoc.CreateElement("message");
element.SetAttribute("System", "ATMS");
element.SetAttribute("Ver", "1.0");
rootNode = xmlDoc.AppendChild(element);
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
//定义子系统
element = xmlDoc.CreateElement("systemtype");
element.InnerText = SubType;
rootNode.AppendChild(element);
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
//定义消息类型
element = xmlDoc.CreateElement("messagetype");
element.InnerText = "ALARM";
rootNode.AppendChild(element);
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
//定义子系统
element = xmlDoc.CreateElement("systemtype");
element.InnerText = SubType;
rootNode.AppendChild(element);
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
//发出消息的源ip地址
element = xmlDoc.CreateElement("sourceIP");
element.InnerText = "";
rootNode.AppendChild(element);
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
//接收消息的目的ip地址
element = xmlDoc.CreateElement("sourceIP");
element.InnerText = "";
rootNode.AppendChild(element);
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
//用户名
element = xmlDoc.CreateElement("user");
element.InnerText = "";
rootNode.AppendChild(element);
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
//密码
element = xmlDoc.CreateElement("password");
element.InnerText = "";
rootNode.AppendChild(element);
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
element = xmlDoc.CreateElement("Alarm");
element.InnerText = "";
rootNode.AppendChild(element);
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
element = xmlDoc.CreateElement("type");
element.InnerText = "";
rootNode.LastChild.AppendChild(element);
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
element = xmlDoc.CreateElement("device");
element.InnerText = "";
subNode=rootNode.LastChild.AppendChild(element);
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
element = xmlDoc.CreateElement("id");
element.InnerText = "";
subNode.AppendChild(element);
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
element = xmlDoc.CreateElement("name");
element.InnerText = "";
subNode.AppendChild(element);
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
element = xmlDoc.CreateElement("location");
element.InnerText = "";
subNode.AppendChild(element);
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
element = xmlDoc.CreateElement("errortype");
element.InnerText = "";
subNode.AppendChild(element);
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
element = xmlDoc.CreateElement("occurtime");
element.InnerText = "";
subNode.AppendChild(element);
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
element = xmlDoc.CreateElement("releasetime");
element.InnerText = "";
subNode.AppendChild(element);
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
element = xmlDoc.CreateElement("desc");
element.InnerText = "";
subNode.AppendChild(element);
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
string x = xmlDoc.OuterXml;
#endregion
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)