// JAXP spec is ambiguous about what really happens in this case,
// so work defensively
Node n = r.getNode();
if( n instanceof Document ) {
return ((Document)n).getDocumentElement();
}
if( n instanceof Element )
return (Element)n;
if( n instanceof DocumentFragment )
return (Element)n.getChildNodes().item(0);
// if the result object contains something strange,
// it is not a user problem, but it is a JAXB provider's problem.
// That's why we throw a runtime exception.
throw new IllegalStateException(n.toString());