users@jaxb.java.net

Re: Find out Object's real Class?

From: Raymond Wold <raymond.wold_at_teletopia.com>
Date: Thu, 06 Sep 2007 08:43:55 +0200

Christopher Holm wrote:
> Hello world,
> I'm having problems with an Object I get from an xml file via JAXB and
> need a few pointers.
>
> toString gives me just
> [real_cst: null]
> and getClass tells me it is an xerces Object:
> class com.sun.org.apache.xerces.internal.dom.ElementNSImpl;
>
> But I don't think I have even installed Xerces, how can this be, how
> do I find out the real type of the object? Any pointers in the right
> direction are very welcome!
>
> (And no, this time it's not a JAXBElement (;)
javap com.sun.org.apache.xerces.internal.dom.ElementNSImpl gives:

public class com.sun.org.apache.xerces.internal.dom.ElementNSImpl extends
com.sun.org.apache.xerces.internal.dom.ElementImpl{

javap com.sun.org.apache.xerces.internal.dom.ElementImpl gives:

public class com.sun.org.apache.xerces.internal.dom.ElementImpl extends
com.sun.org.apache.xerces.internal.dom.ParentNode implements org.w3c.dom.Element{

The clue here is the org.w3c.dom.Element, which is part of the DOM API. So
what you are getting is the dom tree of the contents, and you have to use DOM
methods to traverse it. See
http://java.sun.com/javase/6/docs/api/org/w3c/dom/Element.html