void () { final XmlTag rootTag = XmlElementFactory.getInstance(getProject()).createTagFromText("<ns:tag xmlns:ns=\"xxx\"/>"); WriteCommandAction.runWriteCommandAction(null, () -> { rootTag.setAttribute("foo", "", "bar"); }); assertEquals(2, rootTag.getAttributes().length); assertEquals("bar", rootTag.getAttributeValue("foo")); assertEquals("foo", rootTag.getAttributes()[1].getName()); assertEquals("<ns:tag xmlns:ns=\"xxx\" foo=\"bar\"/>", rootTag.getText()); }