void () { final XmlFile file = (XmlFile)createFile("file.xml", """ <?xml version='1.0' encoding='UTF-8'?> <a> <child> <aboy /> <agirl/> </child> </a>"""); final DomFileElementImpl<MyElement> fileElement = getDomManager().getFileElement(file, MyElement.class, "a"); myCallRegistry.clear(); final MyElement rootElement = fileElement.getRootElement(); rootElement.getChild().getAboy(); rootElement.getChild().getAgirl(); final Document document = getDocument(file); final int len = "<agirl/>".length(); WriteCommandAction.runWriteCommandAction(getProject(), () -> { final int agirl = document.getText().indexOf("<agirl/>"); final int boy = document.getText().indexOf("<aboy />"); document.replaceString(agirl, agirl + len, "<aboy />"); document.replaceString(boy, boy + len, "<agirl/>"); commitDocument(document); }); assertTrue(rootElement.isValid()); final XmlTag tag1 = rootElement.getXmlTag().getSubTags()[0]; assertEquals(getDomManager().getDomElement(tag1.findFirstSubTag("agirl")), rootElement.getChild().getAgirl()); assertEquals(getDomManager().getDomElement(tag1.findFirstSubTag("aboy")), rootElement.getChild().getAboy()); }