tags:

views:

180

answers:

1

How to add an existing Xml string into a XElement?

This code

        var doc = new XDocument(
            new XElement("results", "<result>...</result>")
        );

of course produces this

  <results>&lt;result&gt;&lt;/result&gt;</results>

but I need this

  <results><result>...</result></results>

Any ideas?

+5  A: 

This should work:

var xmlString = "<result>sometext</result>";
var xDoc = new XDocument(new XElement("results", XElement.Parse(xmlString)));
Sani Huttunen
Excellent! I didn't look at class methods. Thank you very much!
r00kie