繁体   English   中英

C#写入特定XML节点

[英]C# Write to Specific XML Node

我有一个xml数据库,格式如下:

<Students>
 <Student ID= *GUID NUMBER*>
  <FullName>John Smith</FullName>
  <Address>Blah blah blah</Address>
  and so on...
 <Student ID= *GUID NUMBER*>
  <FullName>Joe Blow</FullName>
  <Address>Blah Blah</Address>
  and so on...

我有一个组合框,它将从这个xml数据中进行选择,以在其下拉列表中显示FullName。 现在我需要做的是根据在组合框中选择的FullName更新并向所选学生添加节点,一旦按下另一个按钮 - “提交”。

要选择特定的Student节点,您可以:

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
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM