This is relatively easy to implement in an XML Schema or XML DTD. You just need to start to think about the elements differently. XML languages are hierarchal structures. Every single element has only one parent. The fact that elements may use the same name in a particular design, does not mean that they are the same element. This is something that could easily be avoided in language design, but only if markup language concepts are clearly understood.
A group element when it is a child of a groups parent is different than a group element when it is a child of a root element.
The following are two different elements because they come from different parents. The fact that they share the same name does not mean that they are the same element.
In your XML Schema or XML DTD you would simply include only groups as a valid child element. If an XML document violates this rule, then it will be reported when the document is validated against the XML Schema or XML DTD.
How to ensure that a particular child element can only exist under some parent, not alone in xml through xsd?
Do not specifiy that the particular child element is a valid child element. If you specify an element as a valid child the the parser will consider it a valid child. If you do not specify it as a valid child, then the parser will throw an error when it encounters an invalid content model.