leaves[0] = doc.createLeafElement(paragraph, null, 0, 5);
leaves[1] = doc.createLeafElement(paragraph, bold, 5, 9);
leaves[2] = doc.createLeafElement(paragraph, italic, 9, 15);
leaves[3] = doc.createLeafElement(paragraph, null, 15, 16);
((BranchElement) paragraph).replace(0, 1, leaves);
BranchElement branch = (BranchElement) doc.createBranchElement(root, null);
leaves = new Element[1];
leaves[0] = doc.createLeafElement(branch, null, 16, 21);
branch.replace(0, 0, leaves);
// Add this branch to the root
((BranchElement) root).replace(1, 0, new Element[] { branch });
insertOffset = 5 + 2;
}