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
  • 相关阅读:
    【FFMPEG】ffmpeg 时间戳问题汇总
    【FFMPEG】基于RTP的H264视频数据打包解包类
    【FFMPEG】基于RTP的H264视频数据打包解包类
    【FFMPEG】使用FFMPEG+H264实现RTP传输数据
    【FFMPEG】使用FFMPEG+H264实现RTP传输数据
    【FFMPEG】谈谈RTP传输中的负载类型和时间戳
    【FFMPEG】谈谈RTP传输中的负载类型和时间戳
    【图像处理】FFmpeg解码H264及swscale缩放详解
    【图像处理】FFmpeg解码H264及swscale缩放详解
    【图像处理】FFmpeg-0
  • 原文地址:https://www.cnblogs.com/goody9807/p/1538877.html
Copyright © 2011-2022 走看看