Like in any other programming thing ... you need the idea, everything else is simple. THANKS FOR THE IDEA!
Actually things are a lot simpler right now.
Let's say you have HTMLElement <div class="the class">hello man</div>
You want to get the HTMLNode corresponding to this element.
Well we add the random attribute (like you said) and our HTMLElement becomes <div class="the class" my_attr="123124"> hello man</div>
Now we load the htmldocument doc with the new html (that has our element edited) and get the node by using a simple //div[@my_attr='123124']