private static XmlDocument createconfigxmlfile(string servername, string default_dbname,
            string default_dbuser, string default_dbpwd)
        {
            //创建XMLDOCUMENT实例
            XmlDocument doc1 = new XmlDocument();
            //加入XML的声明段落
            XmlDeclaration declaration = doc1.CreateXmlDeclaration("1.0", "uft-8", null);
            doc1.AppendChild(declaration);
            //加入一个根元素
            XmlElement root = doc1.DocumentElement("configuration");
            doc1.AppendChild(root);
            //加入第二级节点1
            XmlElement node2_1 = doc1.CreateElement("connectionstring");
            root.AppendChild(node2_1);
            //在第二级节点1下添加3级节点元素1
            XmlElement node3_1 = doc1.CreateElement("DB");
            string dbstr = string.Format("Data source = {0};initial catalog = {1};user id={2};password={3}",
                servername,default_dbname,default_dbuser,default_dbpwd);
            node3_1.SetAttribute("name", default_dbname);
            node3_1.SetAttribute("connectionstring", dbstr);
            node2_1.AppendChild(node3_1);
            doc1.Save("d:\fffff.xml");
        }        private void Form3_Load(object sender, EventArgs e)
        {
            createconfigxmlfile("broad-97", "sky", "sa", "kitty");
        }
以上报错了,报错位置在 //加入一个根元素
            XmlElement root = doc1.DocumentElement("configuration");
报错的信息是
1 Non-invocable member 'System.Xml.XmlDocument.DocumentElement' cannot be used like a method.  
我一个都看不懂,请各位指教,非常感谢.

解决方案 »

  1.   

    System.Xml.XmlDocument.DocumentElement 不是方法
      

  2.   

    非调用的成员'System.Xml.XmlDocument.DocumentElement'不能像使用方法
    doc1.CreateElement
      

  3.   

    是不是   XmlElement root = doc1.DocumentElement("configuration"); 
    改成   XmlElement root = doc1.CreateElement 就行了呢
      

  4.   

      XmlElement root = doc1.CreateElement("configuration");