0

I want to pass xml formatted text to inner xml text. Is it possible?

 XmlNode parentNode = myTemplate.CreateNode (XmlNodeType.Element, "Parent","myns");
 XmlNode childNode = myTemplate.CreateNode(XmlNodeType.Element, "head", "myns");
 childNode.InnerText = "<paragraph>sample text</paragraph>";
 parentNode.AppendChild(childNode);

but my O/P is coming like

<head>&lt;paragraph&gt;sample text&lt;/paragraph&gt;</head>

desired O/P is

<head><paragraph>sample text</paragraph></head>

Any solution?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
jestges
  • 3,686
  • 24
  • 59
  • 95

2 Answers2

0

When you writer something to InnerText it is HTMLEncoded, this is required otherwise xml parser cannot identify difference between main xml and inner text.

it looks like you want to add inner xml instead of text , for this try childNode.InnerXML instead of childNode.InnerText.

Imran Rizvi
  • 7,331
  • 11
  • 57
  • 101
0

If you use InnerText that will remove the markup. User innerXml instead.

childNode.InnerXml = "<paragraph>sample text</paragraph>";
Kaf
  • 33,101
  • 7
  • 58
  • 78
  • When I try to add InnerXml it is showing sample text. I dont want xmlns="" to be added. Hope you understand – jestges May 16 '12 at 09:39
  • Yes I got it. [Here is a good example](http://stackoverflow.com/questions/987135/how-to-remove-all-namespaces-from-xml-with-c) of how to remove namespaces from xml. – Kaf May 16 '12 at 09:41