需要使用C#中的XML更新一个字符串值 [英] Need to update a string value in XML using C#
本文介绍了需要使用C#中的XML更新一个字符串值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个XML文件,其中有一个特定的字符串需要XML文件进行更新
下面我有@@关键@@
<?XML版本=1.0>?;
<影GT;
<电影名=准备就绪>
<董事GT;约翰和LT; /董事GT;
<下载并GT; HTTP://www.youtube.com/watch V = ** @@关键@@ ** = relatedreadypart6< /下载>
<价格> $ 40℃/价格>
< /电影>
< /影GT;
我想更新@@关键@@一些有效的数据。
解决方案
VAR PATH =C:\path\to\file.xml
VAR的标记= File.ReadAllText(路径);
VAR new_markup = markup.Replace(@@关键@@,富);
变种DOC =新的XmlDocument();
doc.LoadXml(new_markup);
加载文件的字符串。做一个简单的 .Replace
,然后分析它为XML。 new_markup
是字符串
的XML的表示。 商务部
是XML的XML表示。
I have an XML file in which there is a particular string needs to be updated Below in XML File I have "@@key@@"
<?xml version="1.0"?>
<Movies>
<Movie name="Ready">
<Director>John</Director>
<Download>http://www.youtube.com/watch?v=**@@Key@@**=relatedreadypart6</Download>
<Price>$40</Price>
</Movie>
</Movies>
I want to update @@key@@ with some valid Data.
解决方案
var path = "C:\path\to\file.xml";
var markup = File.ReadAllText(path);
var new_markup = markup.Replace("@@key@@", "foo");
var doc = new XmlDocument();
doc.LoadXml(new_markup);
Load the file as string. Do a simple .Replace
and then parse it as XML. new_markup
is a string
representation of the XML. doc
is an XML representation of the XML.
这篇关于需要使用C#中的XML更新一个字符串值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文