void () { final XmlFile file = (XmlFile)PsiFileFactory.getInstance(getProject()).createFileFromText("test.xhtml", "<a>a <b>123</b> c</a>"); final XmlTag tagB = file.getDocument().getRootTag().findFirstSubTag("b"); final XmlTagChild[] tagElements = tagB.getValue().getChildren(); final PsiElement parent = tagB.getParent(); WriteCommandAction.runWriteCommandAction(null, () -> { PsiElement first = parent.addBefore(tagElements[0], tagB); assertNotNull(first); }); }