Tôi mới đến XML
và đã thử làm như sau nhưng tôi nhận được ngoại lệ. Ai đó có thể giúp tôi?Thao tác này sẽ tạo tài liệu có cấu trúc không chính xác
Trường hợp ngoại lệ là This operation would create an incorrectly structured document
Mã của tôi:
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);
}
lỗi gì bạn có? –