C#如何在XML配置文件中添加新属性 [英] C# how to add a new attribute in a XML config file

查看:841
本文介绍了C#如何在XML配置文件中添加新属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

朋友您好,

一个简单的问题。

我需要在xml配置文件中进行以下修改。

需要更换以下内容:



< security mode =TransportCredentialOnly>< transport clientCredentialType =Windows/>



with



< security mode =Transport>

< transport clientCredentialType =WindowsproxyCredentialType =无realm =/>

< message clientCredentialType =UserNamealgorithmSuite =Default/>



如何做到这一点。请帮忙。



我尝试了什么:



我试过google搜索并做了这样的事情......

XmlAttribute formId =(XmlAttribute)xmlDoc.SelectSingleNode(//安全[@模式= 'TransportCredentialOnly'];

如果(formId != null)

{

formId.Value =Transport; //设置为新值。

}

xmlDoc.Save(C:\\ temp \\web.config);



但是没有弄清楚如何添加以下属性:proxyCredentialType,clientCredentialType,algorithmSuite

解决方案
像下面的东西应该工作

 XmlNode的节点=文档。 .SelectSingleNode(// security); 
XmlAttribute attr = doc.CreateAttribute(proxyCredential);
attr.Value =attribute-value;
node.Attributes.Append( ATTR);


Hello friends,
One quick question.
I need to do the following modification in a xml config file.
Need to replace the following:

<security mode="TransportCredentialOnly"><transport clientCredentialType="Windows"/>

with

<security mode="Transport">
<transport clientCredentialType="Windows" proxyCredentialType="None" realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />

How to do this. Please help.

What I have tried:

I tried googling and done something like this...
XmlAttribute formId = (XmlAttribute)xmlDoc.SelectSingleNode("//security[@mode='TransportCredentialOnly'];
if (formId != null)
{
formId.Value = "Transport"; // Set to new value.
}
xmlDoc.Save("C:\\temp\\web.config");

But not getting a clue how to add the following attributes: proxyCredentialType, clientCredentialType, algorithmSuite

解决方案

Something like the following should work.

XmlNode node = doc.SelectSingleNode("//security");
XmlAttribute attr = doc.CreateAttribute("proxyCredential");
attr.Value = "attribute-value";
node.Attributes.Append(attr);


这篇关于C#如何在XML配置文件中添加新属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆