public static void ApplyRecursive(this SvgElement elem, Action<SvgElement> action) { action(elem); if(!(elem is SvgDocument)) //don't apply action to subtree of documents { foreach (var element in elem.Children) { element.ApplyRecursive(action); } } }