2009-11-04 74 views
1

我有以下格式的XML数据库:C#写于特定的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,一旦按下另一个按钮 - “提交”。

+0

您可以包括你如何进行数据绑定它的代码隐藏?这将有助于:) – 2009-11-04 02:45:07

+0

什么框架/ C#版本? – Kev 2009-11-04 02:48:41

回答

4

可以选择特定的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 
}