zoukankan      html  css  js  c++  java
  • XmlDocument,XmlNode,XmlElement创建复杂XML文档

    #region 生成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");
                        element.InnerText 
    = "";
                        subNode.AppendChild(element);

                        element 
    = xmlDoc.CreateElement("name");
                        element.InnerText 
    = "";
                        subNode.AppendChild(element);

                        element 
    = xmlDoc.CreateElement("location");
                        element.InnerText 
    = "";
                        subNode.AppendChild(element);

                        element 
    = xmlDoc.CreateElement("errortype");
                        element.InnerText 
    = "";
                        subNode.AppendChild(element);

                        element 
    = xmlDoc.CreateElement("occurtime");
                        element.InnerText 
    = "";
                        subNode.AppendChild(element);

                        element 
    = xmlDoc.CreateElement("releasetime");
                        element.InnerText 
    = "";
                        subNode.AppendChild(element);

                        element 
    = xmlDoc.CreateElement("desc");
                        element.InnerText 
    = "";
                        subNode.AppendChild(element);

                        
    string x = xmlDoc.OuterXml;
                        
    #endregion
  • 相关阅读:
    Index(4.3)
    第七次会议(4.22)
    第六次会议(4.15)
    第五次会议(4.8)
    第四次会议(4.2)
    第三次会议(3.25)
    第二次扩大会议(3.19)
    第二次会议(3.25)
    第一次会议(3.11)
    牛客练习赛25A求1-x因数和(离散求和)
  • 原文地址:https://www.cnblogs.com/goody9807/p/1538877.html
Copyright © 2011-2022 走看看