void () { WriteCommandAction.runWriteCommandAction(getProject(), () -> { @Language("XML") String xml = "<root>0123456789</root>"; XmlFile file = (XmlFile)PsiFileFactory.getInstance(getProject()) .createFileFromText("foo.xml", XmlFileType.INSTANCE, xml, 1, true, false); XmlTag root = file.getDocument().getRootTag(); final XmlText text1 = root.getValue().getTextElements()[0]; assertFalse(CodeEditUtil.isNodeGenerated(root.getNode())); final XmlText text = text1; final XmlElement element = text.insertAtOffset(XmlElementFactory.getInstance(getProject()).createTagFromText("<bar/>"), 5); assertNotNull(element); assertTrue(element instanceof XmlText); assertEquals("01234", element.getText()); assertEquals("<root>01234<bar/>56789</root>", text.getContainingFile().getText()); }); }