void () { String html = """ <html> <head /> <body xmlns:fabrique="https://www.jetbrains.com/schemas/fabrique/page-template"> <div style="border: 1px solid green; margin: 2px; padding: 2px;"><p><span style="color: red"><span style="font-size: 15pt">12345678</span></span></p></div> </body> </html>"""; XmlFile file = (XmlFile)PsiFileFactory.getInstance(getProject()).createFileFromText("a.xhtml", XHtmlFileType.INSTANCE, html); XmlTag body = file.getDocument().getRootTag().findFirstSubTag("body"); XmlTag span = body.findFirstSubTag("div").findFirstSubTag("p").findFirstSubTag("span").findFirstSubTag("span"); String text = "<span\n style=\"font-size:15pt\">1234</span>"; XmlTag[] tag = {XmlElementFactory.getInstance(getProject()).createXHTMLTagFromText(text)}; WriteCommandAction.runWriteCommandAction(null, () -> { tag[0] = (XmlTag)span.replace(tag[0]); }); assertEquals(text, tag[0].getText()); }