更改XML文档中的值 [英] Change Value in XML-Document
本文介绍了更改XML文档中的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在C#中的这个XML中选择和更改Entwicklung(粗体,unterline)值?
谢谢
问候
妮可
Hi,
how can I select and change the value "Entwicklung" (bold, unterline) in this XML in C#?
Thank you
Regards
Nicole
<?xml version="1.0" encoding="utf-8"?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<!-- Pfad zu log-Verzeichnis -->
<variable name="logDir" value="${specialfolder:folder=ApplicationData}/BAMF/Maris/logs"/>
<variable name="logFile" value="${shortdate}.log"/>
<variable name="umgebung" value="Entwicklung"/>
</nlog>
推荐答案
{specialfolder:folder = ApplicationData} / BAMF / Maris / logs / >
< 变量 名称 = logFile value < span class =code-keyword> =
{specialfolder:folder=ApplicationData}/BAMF/Maris/logs"/> <variable name="logFile" value="
{shortdate} .log / >
< 变量 名称 = umgebung value = Entwicklung / >
< / nlog >
{shortdate}.log"/> <variable name="umgebung" value="Entwicklung"/> </nlog>
你可以使用Xelement类来做到这一点:
http:/ /msdn.microsoft.com/en-us/library/system.xml.linq.xelement_methods.aspx [ ^ ]
如此处所示使用ReplaceWith:
http://stackoverflow.com/questions/5820143/how-can-i-update-replace-an-element-of-an-xelement-from-a-string [ ^ ]
You could use Xelement class to do that:
http://msdn.microsoft.com/en-us/library/system.xml.linq.xelement_methods.aspx[^]
As shown here using ReplaceWith:
http://stackoverflow.com/questions/5820143/how-can-i-update-replace-an-element-of-an-xelement-from-a-string[^]
// input would be your edited XML, this is just sample data to illustrate
string input = @"<Artist Name=""Pink Floyd"">
<BandMembers>
<Member>Nick Mason</Member>
<Member>Syd Barret</Member>
<Member>David Gilmour</Member>
<Member>Roger Waters</Member>
<Member>Richard Wright</Member>
</BandMembers>
<Category>Favorite band of all time</Category>
</Artist>";
var replacement = XElement.Parse(input);
var pinkFloyd = xml.Elements("Genre")
.Where(e => e.Attribute("Name").Value == "Rock")
.Elements("Artist")
.Single(e => e.Attribute("Name").Value == "Pink Floyd");
pinkFloyd.ReplaceWith(replacement);
Console.WriteLine(xml);
这篇关于更改XML文档中的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文