diff --git a/Source/SvgElementCollection.cs b/Source/SvgElementCollection.cs index a13d5f402403f5dd920c1aaed2b274a67d191344..7b5939ab9d1e2e3563827d58b59c291324209736 100644 --- a/Source/SvgElementCollection.cs +++ b/Source/SvgElementCollection.cs @@ -156,7 +156,7 @@ namespace Svg if (this._owner.OwnerDocument != null) { - item.ApplyRecursive(this._owner.OwnerDocument.IdManager.Remove); + item.ApplyRecursiveDepthFirst(this._owner.OwnerDocument.IdManager.Remove); } } } diff --git a/Source/SvgExtentions.cs b/Source/SvgExtentions.cs index dd95152e5719efc5c5c86ace2b557ba166834718..9a93277e6db3ba45e3bf1a1cacbda828e655e701 100644 --- a/Source/SvgExtentions.cs +++ b/Source/SvgExtentions.cs @@ -81,5 +81,18 @@ namespace Svg } } } + + public static void ApplyRecursiveDepthFirst(this SvgElement elem, Action action) + { + if(!(elem is SvgDocument)) //don't apply action to subtree of documents + { + foreach (var element in elem.Children) + { + element.ApplyRecursiveDepthFirst(action); + } + } + + action(elem); + } } }