Nick T
Nick T

Reputation: 321

How to add mixed Text and XElements on XElement value

I am trying to add as value to an XElement mixed text and inline elements.

For example when setting the string "this is a mixed text <foo>and</foo> inline element." the XElement.Nodes to be able to return the text node as XmlNodeType.Text & the element as XmlNodeType.Element.

Thanks in advance.

Upvotes: 1

Views: 399

Answers (1)

Martin Honnen
Martin Honnen

Reputation: 167726

Use e.g. new XElement("parent", "this is a mixed text ", new XElement("foo", "and"), " inline element.") respectively element.Add("this is a mixed text ", new XElement("foo", "and"), " inline element.").

If you have a plain string then use e.g.

element.Add(XElement.Parse("<root>" + "this is a mixed text <foo>and</foo> inline element." + "</root>").Nodes());

Upvotes: 2

Related Questions