Hello all, I'm experiencing a weird issue in trying to load documents in XMLBeans. I'm working with a NetBeans platform application and we use XMLBeans extensively throughout the application. This issue is a "first" for me and I'm not sure how to proceed.
I have an object that stores XML data as a String. So, elsewhere in my application, I have something like this: MyDocument doc = MyDocument.Factory.newInstance(); ... // populate stuff here. String myText = doc.xmlText(); Elsewhere in my application, I want to validate that the String I'm receiving is indeed a valid instance of that document: // Shortened for brevity's sake. public boolean isValid(final String input) { try { MyDocument.Factory.Parse(input); return true; } catch (Exception ex) { } return false; } I get this perplexing error: java.lang.ClassCastException: myPackage.impl.MyDocumentImpl cannot be cast to myPackage.MyDocument So, I put the whole thing in a unit test. I made a document, wrote it to a String, then parsed it again. It works in a unit test. So there must be something going wrong with the environment in my application. Unfortunately, I don't know what that is, nor how to troubleshoot. Here's what I know: - The XMLBeans data is in a single module. There should be no duplicate classes. - I checked the ClassLoader of the MyDocument and MyDocumentImpl classes. They're the same. - I load/edit/save other XMLBeans documents throughout the application without issue. - The string data is stored as child text in another XML element. This may be relevant: String xmlText = myDocument.xmlText(); myOtherElement.setStringValue(xmlText); ... String textToValidate = myOtherElement.getStringValue(); MyDocument.Factory.Parse(textToValidate); Could this be mangling the structure? It looks fine when I log the value. Anyway, further suggestions would be great. Michael