|M| 第一次学习XML 请大家帮改善一下代码 和两个问题
XmlDocument doc = new XmlDocument();
XmlNode node = doc.CreateNode(XmlNodeType.XmlDeclaration, "", "");
doc.AppendChild(node);
XmlElement elem;
XmlText text;
elem = doc.CreateElement("", "config", "");
doc.AppendChild(elem);
elem = doc.CreateElement("ftp");
text = doc.CreateTextNode("");
elem.AppendChild(text);
doc.ChildNodes.Item(1).AppendChild(elem);
elem = doc.CreateElement("user");
text = doc.CreateTextNode("");
elem.AppendChild(text);
doc.ChildNodes.Item(1).AppendChild(elem);
elem = doc.CreateElement("pass");
text = doc.CreateTextNode("");
elem.AppendChild(text);
doc.ChildNodes.Item(1).AppendChild(elem);
elem = doc.CreateElement("path");
text = doc.CreateTextNode("");
elem.AppendChild(text);
doc.ChildNodes.Item(1).AppendChild(elem);
elem = doc.CreateElement("hour");
text = doc.CreateTextNode("");
elem.AppendChild(text);
doc.ChildNodes.Item(1).AppendChild(elem);
doc.Save("config.xml");
上面这样大家会是怎么写的
还有我一般用到对像都是用
XmlElement elem= new XmlElement();
出错:
不可访问,因为它受保护级别限制
在什么情况下不用用: 对像 name =new 对像(); 这样子的呢