Aviv Giladi

Aviv Giladi

  • NA
  • 3
  • 0

Working with XML

Dec 6 2007 7:20 PM

Hey guys,

 

Im looking for a nicer way to replace this code:

 

XmlDocument doc = new XmlDocument();

doc.Load(System.Windows.Forms.Application.StartupPath + @"\groups.xml");

XmlNode newNode = doc.CreateNode(XmlNodeType.Element, "GROUP", "");

string tmp = @"<NAME>" + groupName + @"</NAME>";

for (int i = 0; i < arr.Count; i++)

tmp += @"<VALUE>" + arr[i] + @"</VALUE>";

newNode.InnerXml = tmp;

doc.DocumentElement.AppendChild(newNode);

 

doc.Save(System.Windows.Forms.Application.StartupPath + @"\groups.xml");

 

this should edit an xml document with root named <GROUPS> to give the following format:

<GROUPS>

   <GROUP>

   <NAME>name</NAME>

   <VALUE>12</VALUE>

   <VALUE> 17</VALUE>

   </GROUP>

</GROUPS>


Answers (1)