void () { XmlFile file = (XmlFile)PsiFileFactory.getInstance(getProject()) .createFileFromText("a.xhtml", XHtmlFileType.INSTANCE, """ <a> <b/> </a>"""); XmlTag rootTag = file.getDocument().getRootTag(); XmlTag finalRootTag = rootTag; WriteCommandAction.runWriteCommandAction(null, () -> finalRootTag.getSubTags()[0].delete()); assertEquals(""" <a> </a>""", file.getText()); file = (XmlFile)PsiFileFactory.getInstance(getProject()) .createFileFromText("a.xhtml", XHtmlFileType.INSTANCE, "<html><body><div>text</div></body></html>"); rootTag = file.getDocument().getRootTag(); XmlTag finalRootTag1 = rootTag; WriteCommandAction.runWriteCommandAction(null, () -> { finalRootTag1.getSubTags()[0].getSubTags()[0].setAttribute("a", ""); }); assertEquals("<html><body><div a=\"\">text</div></body></html>", file.getText()); }