Question

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();
 xmldoc.Load(_configFileName);

 string xmlTags = @"<queue name=queueName autoStart=true>
  <deleteFile>true</deleteFile>
  <impersonation enabled=true>
    <user>domain\username</user>
    <password encrypted="true">********</password>
  </impersonation>
  <tasks>
    <task>cp</task>
    <task>rm</task>
  </tasks>
  </queue>";
  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.

Was it helpful?

Solution

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");
        doc.AppendChild(root);
        root.InnerXml = "<child>Hi!</child>";
        doc.Save(Console.Out);
    }
}

OTHER TIPS

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top