|
On Microsoft's XElement: Determining Levels in the Hierarchy of Elements |
|
|
|
|
Written by Daniel Kemper
|
|
Monday, 26 July 2010 15:22 |
|
In working on a Visual Studio 2010 Solution that gives the user a visual rendering of the XML in a configuration (.config) file, I needed a way to determine the level of an XElement within a parent XElement. Here is what I came up with:
public static void FindElementLevel(XElement xParent, XElement xChild) { if (xParent == xChild) { return; } else { ++level; FindElementLevel(xParent, xChild.Parent); } } [Download] (Visual Studio 2010)
|
|
Last Updated ( Monday, 26 July 2010 20:42 )
|