You cannot programmatically add an XMLNode around a selection that includes multiple paragraphs, if the selection begins in the middle of a paragraph and includes a paragraph break.
If you select an area that starts at the beginning of a paragraph, spans more than one paragraph, and ends in the middle of a paragraph, you will see unexpected behavior. When you insert a node, the node begins at the correct point but ends at the end of the last paragraph prior to the end of your selection, instead of at the end of your selection.