void () { final MyElement root = getDomManager().createMockElement(MyElement.class, null, true); WriteCommandAction.writeCommandAction(getProject()).compute(() -> { root.getChild().ensureTagExists(); root.getChild2().ensureTagExists(); final MyElement element = root.addChildElement().getChild(); element.ensureTagExists().getValue().setText("abc"); root.addChildElement(); root.addChildElement(); return element; }); assertTrue(root.isValid()); final MyElement element = root.getChildElements().get(0).getChild(); assertTrue(element.isValid()); final MyElement child = element.getChild(); final MyElement genericValue = child.getChild(); WriteCommandAction.runWriteCommandAction(getProject(), () -> { final Document document = getDocument(DomUtil.getFile(element)); final TextRange range = element.getXmlTag().getTextRange(); document.replaceString(range.getStartOffset(), range.getEndOffset(), ""); commitDocument(document); }); assertFalse(genericValue.isValid()); assertFalse(child.isValid()); assertFalse(element.isValid()); }