【问题标题】:how to add child element to parent in wpf using linq to xml concept?如何使用 linq to xml 概念将子元素添加到 wpf 中的父元素?
【发布时间】:2012-08-09 10:52:49
【问题描述】:
    XElement school = new XElement("school",
                                            new XElement("SectionA",
                                              new XElement("Student", "guna"),
                                              new XElement("Student", "Anbu"),
                                              new XElement("Student", "Chandru")));

 XElement Student = new XElement("Student","Rajesh"); 
 school.Save(@AppDomain.CurrentDomain.BaseDirectory + "Joiningelements.xml");

这里我想在 school 元素中添加 SectionAstudent 子元素。

【问题讨论】:

  • 这和 WPF 有什么关系?

标签: c# xml linq-to-xml


【解决方案1】:

你可以这样使用

XElement Student = new XElement("Student", "Rajesh");

school.Element("SectionA").Add(Student);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-10-31
    • 1970-01-01
    • 1970-01-01
    • 2017-10-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多