fork(1) download
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Collections;
  4. using System.Linq;
  5. using System.Xml;
  6. using System.Xml.Linq;
  7.  
  8. public class Test
  9. {
  10. public static void Main()
  11. {
  12. string xml = @"<Table1>
  13. <buyer_id>0</buyer_id>
  14. <buyername>CompanyA</buyername>
  15. <address1>123 Simpsons Dr.</address1>
  16. <address2/>
  17. <city>Springfield</city>
  18. <state>ST</state>
  19. <postalcode>12345</postalcode>
  20. <eaddress/>
  21. <phone/>
  22. <fax/>
  23. <buyer_id>1</buyer_id>
  24. <buyername>CompanyB</buyername>
  25. <address1>456 Simpsons Dr.</address1>
  26. <address2/>
  27. <city>Springfield</city>
  28. <state>ST</state>
  29. <postalcode>12345</postalcode>
  30. <eaddress/>
  31. <phone/>
  32. <fax/>
  33. </Table1>";
  34.  
  35.  
  36. XDocument doc = XDocument.Parse(xml); //replace with xml file path
  37. IEnumerable<XElement> buyersList = doc.Descendants("Table1"); //get the table node.
  38. var ele = (from buyer in buyersList
  39. where buyer.Element("buyername").Value == "CompanyA"
  40. select buyer).SingleOrDefault();
  41. ele.SetElementValue("address1", "SomeInfo");
  42. ele.SetElementValue("address2", "SomeInfo");
  43.  
  44. Console.WriteLine(ele.Element("address2").Value);
  45. }
  46. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cs(6,18): error CS0234: The type or namespace name `Linq' does not exist in the namespace `System.Xml'. Are you missing an assembly reference?
Compilation failed: 1 error(s), 0 warnings
stdout
Standard output is empty