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.