Fixed flags for BML export

Identified that a bit is set to mark the last in a sequence of child
nodes
This is now used to fixup the nodes before exporting the BML data
Several major fixes for BML export

Rewritten the node logic when exporting BML
Fixed bug checking for siblings (comments treated as nodes)
Fixed bug where the wrong offset was written with a certain flag (0)
Fixed bug with parsing XML comment nodes
Several minor issues with casting