更新自定义配置文件 [英] Update a Custom Config file
问题描述
我想更新下面的配置文件,我将此文件保存为ACE.config文件
Hi,
I want to update the below config file and i am saving this file as ACE.config file
<?xml version="1.0" encoding="utf-8"?>
<ACE xmlns="urn:www.ace.com/services/sol/report/2.3" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Level> report </Level>
<Output>abc </Output>
<Name> </Name>
<Password encrypted="false" alg="2.0" pwd="PhassPhrase" required="Y">plain text</Password>
<delete> Yes</delete>
</ACE>
这里我面临的问题是,如果文件扩展名为.config文件,我无法更新密码标记,如果它是.xml,我能够做到。请帮我更新密码元素的密码属性和innertext。
Here the problem i am facing is, i am not able to update the password tag if file extension is .config file if it is .xml i am able to do. Please help me out to update the password attributes and innertext of the Password Element.
<Password encrypted="false" alg="2.0" pwd="PhassPhrase" required="Y">plain text</Password>
如果要求的值是Y,那么我需要更新encrypted =Trueadn pwd =pwd is encrypted和PlainText(InnerText)到XYZ。
注意:文件的扩展名应为.config
我写下面的代码:更新密码。但它不是全部进入循环
注意:文件的扩展名应为 .config
if required value is Y then i need to update the encrypted ="True" adn pwd="pwd is encrypted" and PlainText (InnerText) to XYZ.
Note : Extension of the file should be .config
I am writting below code : to update the Password. But it''s not all going into for loop
Note : Extension of the file should be .config
XDocument xmlFile = XDocument.Load(@"D:\ACE\ConfigFiles\ACE.config");
var query = from c in xmlFile.Elements("ACE").Elements("Password")
select c;
foreach (XElement password in query)
{
if(password.Attribute("required").Value=="y")
{
password.Attribute("encrypted").Value = "true";
password.Attribute("salt").Value = "PhassPhrase";
password.Value = "EncryptedText";
}
}
// save the XmlDocument back to disk
xmlFile.Save(@"D:\ACE\ConfigFiles\ACE.config");
感谢Advacnce,
Subhash G.
Thanks in Advacnce,
Subhash G.
推荐答案
您好Subash,
在您显示的代码中,如果您更改XML文件扩展名,似乎没有任何行为会有所不同的。扩展在这种情况下没有任何意义。
建议:尝试其他扩展,其他位置,其他名称,看看你得到了什么。 ..
干杯,
Edo
Hi Subash,
In your shown code there seems to be nothing that will behave differently if you change the XML file extension. The extension has no meaning in that context.
Suggestion: try other extensions, other locations, other names, and see what you get...
Cheers,
Edo
这篇关于更新自定义配置文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!