views:

39

answers:

1

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  A: 
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();
Thomas Levesque
this is working fine..if creat a Delet button how to delete the contents
peter
the contents of what ?
Thomas Levesque
okey deleting same thing
peter
I still don't understand... do you want to delete the `<Destination>` element ?
Thomas Levesque
it may be destination tag or it may be name tag..it shud be user driven
peter
see updated answer
Thomas Levesque