如果有返回基於目錄創建目錄結構的XML DOM
private static TreeNode GetDirectoryNodes(string path)
{
var dir = new DirectoryInfo(path);
var node = new TreeNode(dir.Name);
foreach (var directory in dir.GetDirectories())
{
node.Nodes.Add(GetDirectoryNodes(path + "\\" + directory.ToString()));
}
return node;
}
不過,我需要創建目錄stucture的XML DOM一個TreeNode的方法,不過,我是新來的XML DOM和無法弄清楚如何做到這一點。我看到的問題是:如何將\放入XML中;以及如何獲得子目錄這是我到目前爲止
private static XmlDocument GetDirTreeData(string path)
{
var dir = new DirectoryInfo(path);
XmlDocument XMLDOM = new XmlDocument();
XmlElement xl = XMLDOM.CreateElement(path);
foreach (var directory in dir.GetDirectories())
{
xl.InnerXml = directory.ToString();
}
return XMLDOM;
}
喔......另一個** **非linq2xml solution..use ** ** linq2Xml ..其該死的簡單比'XmlDocument' – Anirudha