Document Models

Why, oh, why did the Google Wave folks feel that they needed to invent a brand-new document model? It's XML, sort of. Except from the robots API the document looks like a text string to which you can apply annotations and insert elements. Except that figuring out the correct offsets within that text string is all screwy.

I'm trying to write a simple robot which substitutes card images for card names inside a Wave. There are plenty of examples of people doing something like this, which should make it easy.

However, when I call Document.InsertElement to place an image inside some newly-created text, it works fine for the first image. But the second image is two characters too early, and the next is four characters too early. So I guess the answer is just to insert a 'fudge factor' of 2 characters, but I don't know why.