void () { Project ideaProject = getProject(); PsiManager psiManager = PsiManager.getInstance(ideaProject); XmlFile fileFromText = (XmlFile)PsiFileFactory.getInstance(psiManager.getProject()) .createFileFromText("sample.xhtml", XHtmlFileType.INSTANCE, "<html><body><p/></body></html>", LocalTimeCounter.currentTime(), true); XmlTag htmlTag = fileFromText.getDocument().getRootTag(); XmlTag bodyTag = htmlTag.getSubTags()[0]; XmlTag tagP = bodyTag.getSubTags()[0]; //do not remove: to hold the reference //noinspection unused Document document = PsiDocumentManager.getInstance(ideaProject).getDocument(htmlTag.getContainingFile()); execute(() -> CodeStyleManager.getInstance(ideaProject).performActionWithFormatterDisabled((Runnable)() -> { try { XmlTag childTag = XmlElementFactory.getInstance(getProject()).createXHTMLTagFromText("<p/>"); bodyTag.addAfter(childTag, tagP); } catch (IncorrectOperationException ignored) { } })); assertEquals("<html><body><p/><p/></body></html>", htmlTag.getText()); }