TL;DR Check out the Adding ids to Header Nodes section to see how to use the Visitor Pattern.
I recently wanted to add an id to every header tag in an HTML string. This sounds like an easy task right? A little jQuery and the problem is solved:
$(":header").attr("id", "1") is a rough solution.
This is a story of parsing, recursing, and modifying raw HTML without comfortable, declarative APIs. It's surprisingly approachable with the help of the Visitor pattern.