0

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.

1
  • Look at XmlDocument and XDocument. Then, try some things. It is just using a simple XPath Selector coupled with updating the element Value. Alternatively, just treat the entire file as a string (and use string.Replace or RegExp.Replace) since it seems like a very specialized problem. Commented Aug 17, 2011 at 17:02

2 Answers 2

2
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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks a lot that's exactly what I want.
1
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(string.replace(xmlStr, " @@key@@","your data"))

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.