void () { final XmlTag rootTag = XmlElementFactory.getInstance(getProject()).createTagFromText("<html/>"); final String value = "a \"b\" c"; WriteCommandAction.runWriteCommandAction(null, () -> { rootTag.setAttribute("foo", value); }); assertEquals(1, rootTag.getAttributes().length); assertEquals(value, rootTag.getAttributeValue("foo")); assertEquals("foo", rootTag.getAttributes()[0].getName()); assertEquals("<html foo='" + value + "'/>", rootTag.getText()); }