2011-10-07 161 views

回答

1

這遞歸返回節點的所有父元素:

public static IEnumerable<XElement> Parents(this XObject obj) 
{ 
    XElement e = obj.Parent; 
    while (e != null) 
    { 
     yield return e; 
     e = e.Parent; 
    } 
} 

如果你想只包含節點及其父母的文件,你需要刪除,雖然所有其他節點。

相關問題