This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
When you say "cast" it implies that an xml element is a java type. I may be wrong but, in my experience, I always create an XML just like you'd create a String (appending tags and values as needed). I usually have all the values as fields in a class (CMRAll in my example) so I can loop through all the fields to create the element names and values using the Class class in a method I call "xmlIt". The result is a String with the entire xml structure, like this:
I'm willing to listen to someone with a better idea since I am relatively new to creating xml from my code.