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