XmlTag (@NotNull final Project project, boolean inHeader) { final String filetext = "<root>" + (inHeader ? "<th></th>" : "<td></td>") + "</root"; final XmlFile xmlFile = (XmlFile)PsiFileFactory.getInstance(project).createFileFromText("dummy.xml", XMLLanguage.INSTANCE, filetext); XmlTag tag = xmlFile.getDocument().getRootTag(); for (PsiElement element : tag.getChildren()) { if (element instanceof XmlTag) { tag = (XmlTag)element; } } return tag; }