How to add an existing Xml string into a XElement

后端 未结 3 1173
醉酒成梦
醉酒成梦 2020-12-11 00:53

How to add an existing Xml string into a XElement?

This code

        var doc = new XDocument(
            new XElement(\"results\", \".         


        
3条回答
  •  春和景丽
    2020-12-11 01:12

    See my answer on Is there an XElement equivalent to XmlWriter.WriteRaw?

    Essentially, replace a placeholder for the content only if you know it's already valid XML.

    var d = new XElement(root, XML_PLACEHOLDER);
    var s = d.ToString().Replace(XML_PLACEHOLDER, child);
    

    This method may also be faster than parsing it with XElement.Parse.

提交回复
热议问题