void () { final XmlFile xmlFile = createXmlFile("<a xmlns:sys=\"\"/>"); final MyElement element = getDomManager().getFileElement(xmlFile, MyElement.class, "a").getRootElement(); final MyElement hardcodedElement = element.getHardcodedElement(); WriteCommandAction.runWriteCommandAction(getProject(), () -> { hardcodedElement.ensureTagExists(); }); assertTrue(element.isValid()); assertTrue(hardcodedElement.isValid()); assertNotNull(hardcodedElement.getXmlElement()); assertEquals("<sys:aaa/>", hardcodedElement.getXmlElement().getText()); assertEquals("sys:aaa", hardcodedElement.getXmlTag().getName()); WriteCommandAction.runWriteCommandAction(getProject(), () -> { hardcodedElement.getHardcodedElement().getHardcodedElement().ensureTagExists(); }); assertTrue(element.isValid()); assertTrue(hardcodedElement.isValid()); assertNotNull(hardcodedElement.getXmlElement()); assertEquals("sys:aaa", hardcodedElement.getHardcodedElement().getHardcodedElement().getXmlTag().getName()); assertEquals(1, element.getXmlTag().getSubTags().length); }