precedingWhitespace is an attribute of Node, but the parser uses it only for Elements. I wonder whether it is intentional? Should it not also be set on Comments, where the parser currently prepends a Text node? (Not sure what is the behavior on ProcessingInstruction and Document).