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

string xmlstr1 = @"myHead";
            string xmlstr2 = @"11";
            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 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(string xmlstr)
        {
            XmlSerializer xmlSerializer = new XmlSerializer(typeof(T));
            using (XmlReader reader = new XmlTextReader(new StringReader(xmlstr)))
            {
                return (T)xmlSerializer.Deserialize(reader);
            }
        }

  

你可能感兴趣的:(xmldocument内嵌入另一个xmldocument,xmlnode的方法)