2011-10-07 160 views

回答

1

这递归返回节点的所有父元素:

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

如果你想只包含节点及其父母的文件,你需要删除,虽然所有其他节点。

相关问题