Take the 2-minute tour ×

Is there anyway I can create nodes out of a string? I've searched the Web looking for something, but couldn't find anything that works!

 string _configFileName = @"d:\junk\config.xml";
 XmlDocument xmldoc = new XmlDocument();

 string xmlTags = @"<queue name=queueName autoStart=true>
  <impersonation enabled=true>
    <password encrypted="true">********</password>
  queueParent.InnerText = str;//the Xml parent node of the new queue node that I want to add
   xmldoc.Save();//will write &lt;queue name= INSTEAD OF <queue name=

So the problem is having the special characters in XML "<" and ">" written into the file as "<" and ">". Your input is much appreciated, thanks.

share|improve this question

2 Answers 2

up vote 1 down vote accepted

I think you want the InnerXml property instead of InnerText.

For example:

using System;
using System.Xml;

class Test
    static void Main()
        XmlDocument doc = new XmlDocument();
        XmlElement root = doc.CreateElement("root");
        root.InnerXml = "<child>Hi!</child>";
share|improve this answer
thanks, it worked fine. I tried it yesterday and didn't work. It was a long day perhaps! thanks again. –  Derar Sep 2 '09 at 17:19

You can create an XmlDocument from a string using xmldoc.LoadXml(xmlTags)

share|improve this answer
yeah, that's another option that works for me. I wanted something with less headache. but you have to use someNode.AppendChild(doc.ImportNode(rolesNode,true )); to add it to the first DOM-tree as you are building a new DOM-tree. –  Derar Sep 2 '09 at 17:23

Your Answer


