• xmldocument内嵌入另一个xmldocument,xmlnode的方法


    string xmlstr1 = @"<root><head>myHead</head><body></body></root>";
                string xmlstr2 = @"<so><num>1</num><sodetail><num>1</num></sodetail></so>";
                XmlDocument doc1 = new XmlDocument();
                doc1.LoadXml(xmlstr1);
                XmlDocument doc2 = new XmlDocument();
                doc2.LoadXml(xmlstr2);
                object a= doc2.FirstChild;
                XmlNode ch = doc1.ImportNode(doc2.DocumentElement, true);
                XmlNode node1 = doc1.SelectSingleNode("/root/body");
                node1.AppendChild(ch);
    

      

     private static string ConvertToXML<T>(T msg)
            {
                XmlSerializerNamespaces xmlnsEmpty = new XmlSerializerNamespaces();
                xmlnsEmpty.Add("", "");
    
                System.Xml.Serialization.XmlSerializer xmlser = new System.Xml.Serialization.XmlSerializer(typeof(T));
                StringBuilder sb = new StringBuilder();
                using (XmlWriter writer = XmlWriter.Create(sb, new XmlWriterSettings { OmitXmlDeclaration = true }))
                {
                    xmlser.Serialize(writer, msg, xmlnsEmpty);
                }
                //System.Threading.Thread.Sleep(5000);
                return sb.ToString();
            }
            private static T ConvertToObject<T>(string xmlstr)
            {
                XmlSerializer xmlSerializer = new XmlSerializer(typeof(T));
                using (XmlReader reader = new XmlTextReader(new StringReader(xmlstr)))
                {
                    return (T)xmlSerializer.Deserialize(reader);
                }
            }
    

      

  • 相关阅读:
    Docker可视化管理工具Portainer
    Spring Cloud,Docker书籍资源、优秀博文等记录
    Grafana部署监控docker服务
    Grafana+Prometheus通过node_exporter监控Linux服务器信息
    Prometheus+Grafana+kafka_exporter监控kafka
    k8s gpu 资源设置
    mysql 塞数据
    idea 插件
    ubuntu 升级内核
    清华镜像站安装docker
  • 原文地址:https://www.cnblogs.com/neozhu/p/3202393.html
Copyright © 2020-2023  润新知