JAXB issue with missing namespace definition



So I searched around quite a bit for a solution to this particular issue and I am hoping someone can point me in a good direction.


We are receiving data as XML, and we only have XSD to validate the data. So I used JAXB to generate the Java classes. When I went to unmarshal a sample XML, I found that some attribute values are missing. It turns out that the schema expects those attributes to be QName, but the data provider didn't define the prefix in the XML.


For instance, one XML attribute value is "repository:", but the namespace prefix "repository" is never defined in the dataset. (Never mind the provider's best practices suggest defining it!)


So when I went to unmarshal a sample set, the QName attributes with the specified prefix ("repository" in my sample above) are NULL! So it looks like JAXB is "throwing out" those attribute QName values which have undefined namespace prefix. I am surprised that it doesn't preserve even the local name.


Ideally, I would like to maintain the value as is, but it looks like I can't map the QName to a String at binding time (Schema to Java).


I tried "manually" inserting a namespace definition to the XML and it works like a charm. What would be the least complicated method to do this?


Is there a way to "insert" namespace mapping/definition at runtime? Or define it "globally" at binding time?


No comments:

Post a Comment