Simplify node logic

The only effect of setting p to 0 here is to break the loop, using break is much simpler.
As for line 858, there is no point to set node to 0 and then break the loop right after.
If there was a mismatch, 'node' will be deleted, but not null. And then InsertEndChild will be called with a dangling pointer?