Remove child throws exception
See the question and my original answer on StackOverflowSince you're getting all spans recursively under the current node (that's what // means in XPATH), you may get a span that is not a child of node, but a grand child.
In this case the call node.RemoveChild(span) will fail as you see. What you want to do instead is span.ParentNode.RemoveChild(span).