0

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.

Nick T
  • 311
  • 2
  • 5

1 Answers1

2

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());
Martin Honnen
  • 160,499
  • 6
  • 90
  • 110