I am a newbie in Java and I have a unique requirement. I am getting xml data from client and I had already defined schema with me. Now, the problem is client side xml has many more element than schema I have. How to deal with it? Further, there are some elements which have different architecture then what is defined in schema, I want to transform it into form of what schema has. Does it sound wrong since schema is generally there for validating? Can someone give me overview of how to deal with the problem with small example?
The purpose of an XML schema is to describe the structure of a set of XML documents. If your client is sending XML which does not conform to your schema, then one of three things must be true:
The client is incorrect. If so, you should reject their request as it is not valid.
Your schema is incorrect. In this case, you should correct your schema so that it describes exactly what is permitted in requests.
Your schema is describing something else entirely. In this case, you should write another schema which does describe the permitted requests. You may want then want to transform documents matching this schema into documents matching your new schema - XSLT is a great tool for doing exactly this. I notice you've tagged JAXB too - another way to perform the transformation would be to construct JAXB representations of both schemas and perform the conversion yourself in code.
Is this helpful? I'd say first and foremost, you need to work out what role your XML schema is performing in your system, and that's a design task you should do before you start writing any code.