void () { XmlFile xhtmlFile = (XmlFile)PsiFileFactory.getInstance(getProject()).createFileFromText("dummy.xhtml", "<html/>"); final XmlTag rootTag = xhtmlFile.getDocument().getRootTag(); WriteCommandAction.runWriteCommandAction(null, () -> { rootTag.setAttribute("foo", "bar"); }); assertEquals(1, rootTag.getAttributes().length); assertEquals("bar", rootTag.getAttributeValue("foo")); assertEquals("foo", rootTag.getAttributes()[0].getName()); }