[英]innerText of XmlNode from a String
无论如何,我可以用字符串创建节点吗? 我已经在网上搜索了一些东西,但找不到任何有效的方法!
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 <queue name= INSTEAD OF <queue name=
因此,问题在于将XML“ <”和“>”中的特殊字符分别写为“ <”和“>”。 感谢您的输入。
我认为您想要InnerXml
属性而不是InnerText
。
例如:
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);
}
}
您可以使用xmldoc.LoadXml(xmlTags)从字符串创建XmlDocument。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.