You seem to have fallen into the common error of believing that the prefix is the important part of the namespace. It isn't. The namespace URI is what defines the namespace, and the prefix is just a meaningless string for the convenience of XML authors.

In the first example you have a "{http://www.example1.org/xml/sample}category" attribute and then you have a "{http://www.example2.org/xml/sample}category" attribute. These have different names.

In the second example you have two "{http://www.example.org/xml/sample}category" attributes. They have the same name.

And in the third example you also have two "{http://www.example.org/xml/sample}category" attributes, which have the same name.

>I know that first example is a valid one, second is invalid,... To be more precise, the first example is well-formed, the second is not. Despite the apparent of having some xsd schema referred in the root, it has nothing to do with the validation which has never begun to begin.

ps: As to the second figurative explanation starting with xmlns:yourname etc... and ending with Rajani:category etc..., on the face of it reverting namespace uri to namespace prefix: I can see what is intended to convery, but, it risks to distort the issue with more confusion. But, again, I see what is intended to convey and I have no problem with the hidden message.

subject: Condition on attributes : Can an element has same attribute from two different namespaces