Reputation: 25
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.
Upvotes: 0
Views: 217
Reputation: 14279
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.
Upvotes: 2
Reputation: 6999
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(string.replace(xmlStr, " @@key@@","your data"))
Upvotes: 1