void (final XmlElement tag, final List<FoldingDescriptor> foldings, final Document document) { final PsiElement[] children = tag.getChildren(); for (PsiElement child : children) { ProgressManager.checkCanceled(); if (child instanceof XmlTag || child instanceof XmlConditionalSection) { addElementsToFold(foldings, (XmlElement)child, document); } else if (child instanceof XmlComment) { addToFold(foldings, child, document); } else if (child instanceof XmlText || child instanceof XmlProlog) { final PsiElement[] grandChildren = child.getChildren(); for (PsiElement grandChild : grandChildren) { ProgressManager.checkCanceled(); if (grandChild instanceof XmlComment || isEntity(grandChild)) { addToFold(foldings, grandChild, document); } } } else if (isEntity(child) || child instanceof XmlAttribute && isAttributeShouldBeFolded((XmlAttribute)child)) { addToFold(foldings, child, document); } else { final Language language = child.getLanguage(); if (!(language instanceof XMLLanguage) && language != Language.ANY || child instanceof HtmlEmbeddedContentImpl) { final FoldingBuilder foldingBuilder = LanguageFolding.INSTANCE.forLanguage(language); if (foldingBuilder != null) { final FoldingDescriptor[] foldingDescriptors = foldingBuilder.buildFoldRegions(child.getNode(), document); ContainerUtil.addAll(foldings, foldingDescriptors); } } } } }