【发布时间】:2012-12-29 12:48:09
【问题描述】:
我是 XML 的新手,并尝试了以下操作,但遇到了异常。有人能帮我吗?
例外是This operation would create an incorrectly structured document
我的代码:
string strPath = Server.MapPath("sample.xml");
XDocument doc;
if (!System.IO.File.Exists(strPath))
{
doc = new XDocument(
new XElement("Employees",
new XElement("Employee",
new XAttribute("id", 1),
new XElement("EmpName", "XYZ"))),
new XElement("Departments",
new XElement("Department",
new XAttribute("id", 1),
new XElement("DeptName", "CS"))));
doc.Save(strPath);
}
【问题讨论】:
标签: c# asp.net .net linq linq-to-xml