我正在嘗試構建一個動態XDoc,其中包含一個工具用作「路徑」的文件夾列表。每個 「文件夾」 元件是在樹另一層XDocument XElement構造函數
實施例:
Root Level
-- Folder L0
-- Folder L1
-- Folder L2
這是在XML表示如下:
<FolderPath>
<Folder>L0</Folder>
<Folder>L1</Folder>
<Folder>L2</Folder>
</FolderPath>
我的代碼如下:
// Build up the innermost folders inside the Folderpath element dynamically
XElement folderPath = new XElement();
folderPath.Add(new XElement(FolderList[0],
new XAttribute("fromDate", FromDate),
//attributes for Folder w/ lots of attributes
new XAttribute("toDate", ToDate),
new XAttribute("contactName", ContactName),
new XAttribute("email", Email),
FolderList[0]));
for (int i = 1; i < FolderList.Count; i++)
{
folderPath.Add(new XElement(FolderList[i]));
}
FolderList是我在代碼中的這一點之前填充的列表。但是我有問題,與線路:
XElement folderPath = new XElement();
什麼是落實的XElement,這樣我可以動態地添加包含在FolderList文件夾的好方法?我得到的錯誤是「System.Xml.Linq.XElement不包含一個構造函數,它接受0個參數」。
這幾乎是一歲,但我碰到它,同時尋找一些答案的XElement,你仍然需要任何幫助?如果你有一個你想要得到的XML看起來如何的例子,我可以找出一些可行的方法。 – Zack