0

i have an xml file sitemap.xml as shown below ..i need to add one more

tag here after <Name> tag..Means After <Name>test</Name> tag here

i need to add destination tag like <Destination>NY</Destination>

.Can we add contents to xml through a textbox by pressing a button control without manually doing

this is xml file sitemap.xml

<?xml version="1.0" encoding="utf-8" ?>
<ObjectClass>
  <Image>00000000-0000-0000-0000-000000000000</Image>
  <Description />
  <Name>test</Name>
  <DefaultApp>00000000-0000-0000-0000-000000000000</DefaultApp>
  <ID>464930eb-e518-4d0c-b80b-184c97c7dd27</ID>
  <ParentClassID>00000000-0000-0000-0000-000000000002</ParentClassID>
  <DynamicPopulation>false</DynamicPopulation>
  <TimeoutPeriod>0</TimeoutPeriod>
  <Persist>false</Persist>
  <ClassVersion>1</ClassVersion>
  <Reinitialize>false</Reinitialize>
</ObjectClass>

1 Answer 1

1
XmlDocument doc = new XmlDocument();
doc.Load(fileName);
XmlElement elt = doc.CreateElement("Destination");
elt.InnerText = "NY";
doc.DocumentElement.AppendChild(elt);
doc.Save(fileName);

To delete an element :

XmlDocument doc = new XmlDocument();
doc.LoadXml(xml);
XmlElement elt = doc.DocumentElement.SelectSingleNode("Destination") as XmlElement;
if (elt != null)
    doc.DocumentElement.RemoveChild(elt);
doc.Save();
Sign up to request clarification or add additional context in comments.

3 Comments

this is working fine..if creat a Delet button how to delete the contents
I still don't understand... do you want to delete the <Destination> element ?
it may be destination tag or it may be name tag..it shud be user driven

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.