users@jaxb.java.net

Re: Find out Object's real Class?

From: Christopher Holm <them4z_at_googlemail.com>
Date: Thu, 6 Sep 2007 11:03:37 +0200

On 9/5/07, Malachi de Ælfweald <malachid_at_gmail.com> wrote:
> I *think* what you are wanting is the actual object created by the element,
> not the xml element itself - right? Can you post your code snippet?
Right, or rather a way to access the data in it. Since I neither knew
what the actual type was nor have Xerces installed, I was a bit
clueless how to handle the thing.

The xml-files snippet is not thaaat hard to interpret:
    <real_cst>
        3.14159265000000020862103156105149537324905395508e+0
    </real_cst>


But I just didn't know how to access it. The JAXB-generated code looks
like this:
        /**
         * Gets the value of the realCst property.
         *
         * @return
         * possible object is
         * {_at_link Object }
         *
         */
        public Object getRealCst() {
            return realCst;
        }

        /**
         * Sets the value of the realCst property.
         *
         * @param value
         * allowed object is
         * {_at_link Object }
         *
         */
        public void setRealCst(Object value) {
            this.realCst = value;
        }
...which is not that informative \:


On 9/6/07, Raymond Wold <raymond.wold_at_teletopia.com> wrote:
> 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
Thanks! Now it was easy to get at it...

        public static String translateRealCst(Object o){
                String ret = "";
                if(o instanceof Element){
                        Element e = (Element)o;
                        ret = ret + e.getFirstChild().getNodeValue().trim();
                }
                return ret;
        }


-- 
Mit freundlichen Grüßen,
    Christopher "m4z" Holm