如果选择单个节点为空,则创建单个节点
我有一个更新配置文件的程序。例如,配置文件可能包含:
<configuration>
<userSettings>
<setting name="phoneNumber" serializeAs="String">
<value>123-456-7890</value>
</setting>
</userSettings>
</configuration>
要更新此配置文件,我使用以下命令:
XmlNode phoneNumberNode = theConfig.SelectSingleNode("configuration/userSettings/setting[@name='phoneNumber']");
phoneNumberNode.FirstChild.InnerText = this._cloudPublisherWebURL;
现在,在更新过程中我想更新电话号码和地址。地址可能存在于配置文件中,也可能不存在。
如果 SelectSingleNode 为 null,我想创建一个具有给定路径的节点并设置其值。
XmlNode addressNode = theConfig.SelectSingleNode("configuration/userSettings/setting[@name='address']");
if(addressNode == null)
{
//..Create the node here
}
如何在给定路径上创建具有值的节点?
I have a program that updates a config file. For example, the config file may contain:
<configuration>
<userSettings>
<setting name="phoneNumber" serializeAs="String">
<value>123-456-7890</value>
</setting>
</userSettings>
</configuration>
To update this config file, I use the following:
XmlNode phoneNumberNode = theConfig.SelectSingleNode("configuration/userSettings/setting[@name='phoneNumber']");
phoneNumberNode.FirstChild.InnerText = this._cloudPublisherWebURL;
Now, during the update I want to update phoneNumber and address. Address may or may not be in the config file.
If SelectSingleNode is null, I would like to create a node with the given path and set its value.
XmlNode addressNode = theConfig.SelectSingleNode("configuration/userSettings/setting[@name='address']");
if(addressNode == null)
{
//..Create the node here
}
How can I create the node with value at the given path?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)