void () { final XmlTag tagA = XmlElementFactory.getInstance(getProject()).createXHTMLTagFromText("<a>1<b>&nbsp;</b></a>"); final XmlTag tagB = tagA.findFirstSubTag("b"); final XmlTagChild nbsp = tagB.getValue().getChildren()[0]; assertEquals("&nbsp;", nbsp.getText()); ApplicationManager.getApplication().runWriteAction(() -> { tagA.addBefore(nbsp.copy(), tagB); }); XmlTagChild nbsp1 = tagA.getValue().getChildren()[0]; assertEquals("1&nbsp;", nbsp1.getText()); }