开发者

C# Write to Specific XML Node

I have a xml database with the following format:

<Students>
 <Student ID= *GUID NUMBER*>
  <FullName>John Smith</FullName>
  <Address>Blah blah blah</Address>
  and so on...
 <Student ID= *GUID NUMBER*>
  <FullName>Joe B开发者_如何学Clow</FullName>
  <Address>Blah Blah</Address>
  and so on...

I have a combobox that will select from this xml data to display the FullName in its dropdown. Now what I need to do is have other fields to update and add nodes to the chosen Student based on what FullName is chosen in the combobox, once another button - "Submit" is pressed.


To select your specific Student node, you could do:

XmlDocument xml = new XmlDocument();
xml.LoadXml("<Students>...."); // or xml.Load("yourfile.xml");
XmlElement student = xml.SelectSingleNode(
    String.Format("//Student[@ID='{0}']",
                  yourcombo.SelectedItem.Value)) as XmlElement;
if(student != null)
{
    XmlElement another = xml.CreateElement("another");
    another.InnerText = "Value";
    student.AppendChild(another);

    // do other stuff
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜