How to put attributes via XElement

后端 未结 1 1657
半阙折子戏
半阙折子戏 2020-12-02 17:45

I have this code:

XElement EcnAdminConf = new XElement(\"Type\",
    new XElement(\"Connections\",
    new XElement(\"Conn\"),
    // Conn.SetAttributeValue(         


        
相关标签:
1条回答
  • 2020-12-02 18:37

    Add XAttribute in the constructor of the XElement, like

    new XElement("Conn", new XAttribute("Server", comboBox1.Text));
    

    You can also add multiple attributes or elements via the constructor

    new XElement("Conn", new XAttribute("Server", comboBox1.Text), new XAttribute("Database", combobox2.Text));
    

    or you can use the Add-Method of the XElement to add attributes

    XElement element = new XElement("Conn");
    XAttribute attribute = new XAttribute("Server", comboBox1.Text);
    element.Add(attribute);
    
    0 讨论(0)
提交回复
热议问题