1
Answer

Working with XML

Aviv Giladi

Aviv Giladi

16y
2k
1

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)