};
doc.buffer = buf;
doc.writeLock();
try {
doc.getContent().insertString(0, "\n0000");
final BranchElement html = (BranchElement) root;
html.addAttribute(ELEMENT_NAME, "html");
final BranchElement head = createBranch(html);
head.addAttribute(ELEMENT_NAME, "head");
final BranchElement implied = createBranch(head);
implied.addAttribute(ELEMENT_NAME, "p-implied");
final LeafElement content0 = createLeaf(implied, 0, 1);
content0.addAttribute(ELEMENT_NAME, "head-content");
final BranchElement body = createBranch(html);
body.addAttribute(ELEMENT_NAME, "body");
final BranchElement p1 = createBranch(body);
p1.addAttribute(ELEMENT_NAME, "p1");
final LeafElement content1 = createLeaf(p1, 1, 5);
content1.addAttribute(ELEMENT_NAME, "leaf1");
final LeafElement content2 = createLeaf(p1, 5, 6);
content2.addAttribute(ELEMENT_NAME, "leaf2");
implied.replace(0, 0, new Element[] { content0 });
p1.replace(0, 0, new Element[] { content1, content2 });
head.replace(0, 0, new Element[] { implied });
body.replace(0, 0, new Element[] { p1 });
html.replace(0, 1, new Element[] { head, body });
} finally {
doc.writeUnlock();