add data to existing xml file using linq

mustangsjj

New Member
I am a .net beginner. I need to add some data to xml filethe xml file is:\[code\]<stock> --- 1st level /* i dont want to create this because this exists */ <items> -- 2nd level <productname>Toothpaste</productname> <brandname>Colgate</brandname> <quantity>12</quantity> <price>10</price> </items> <items> <productname>Toothpaste</productname> <brandname>Pepsodent</brandname> <quantity>20</quantity> <price>12</price> </items></stock>\[/code\]I need to add \[code\]productname --> Toothpastebrandname --> CloseUpquantity --> 16price --> 15\[/code\]to their respective tags. The problem I am facing now is that I need to go two levels deep to write to their respective tags, which i dont know how to do.I tried the below code: (not working)\[code\]XDocument doc = new XDocument( new XElement("stock", /* how to go inside existing "stock"? */ new XElement("items", new XElement("productname", "Toothpaste"), new XElement("brandname", "CloseUp"), new XElement("quantity","16"), new XElement("price","15"))));\[/code\]There must be some other way to achieve this which I dont know.
Answers not related to linq are also welcome. but more preference to linq because I have implemented full linq in my project.Please Help
Thanks in Advance.
 
Back
Top