This part goes over my head; I see you are accounting for attribute names being possibly all lowercase, but presumably you won't be able to handle something like foobarattr="x" where it's supposed to correspond to a property called "fooBar"?

Maybe you don't care about that limitation.