The correct way to do it would be:
if (xo instanceof XmlAnySimpleType)
return ((XmlAnySimpleType) xo).getStringValue();
Radu
> -----Original Message-----
> From: Siegfried Baiz [mailto:[EMAIL PROTECTED]
> Sent: Sunday, November 16, 2008 6:08 AM
> To: [email protected]
> Subject: Re: XMLBeans : How can I get a value and not an xml fragment?
>
> Hi, I had to face a related Problem recently:
>
> How to get a (java)-value from an XmlObject without knowing
> its actual type?
>
> Actually I'm doing something like this:
>
> Object=getValue(XmlObject xo){
> if (xo instanceof
> org.apache.xmlbeans.impl.values.XmlObjectBase){
> return ((XmlObjectBase)xo).getObjectValue()
> }else{
> // trying to extract textValue from Cursor
> return getTextValue(xo.newCursor()); // dispose Cursor inside!
> }
> }
>
>
> I keep on searching for a a better way
> avoiding the usage of org.apache.xmlbeans.impl.* Thanks in
> advance for any hints.
>
> Siggi B.
>
> ----------------
>
>
>
>
> Jacob Danner wrote:
> > I'm not sure how the type is defined, but aren't there getters and
> > setters or something like intValue() to get this.
> >
> > You are seeing this because getM() returns some kind of type
> > associated with xml (element in this case) and not some
> kind of java
> > primitive.
> > The docs explain things far better than I can
> > (http://xmlbeans.apache.org/documentation/index.html) take
> a peek and
> > let the list know if you have any questions.
> >
> > HTH,
> > -jacobd
> >
> > On Sat, Nov 15, 2008 at 4:36 PM, MattC123
> <[EMAIL PROTECTED]> wrote:
> >
> >> I've just started using XMLBeans (read newbie) and I've run into a
> >> problem. I have a simple element and I am trying to get
> the value of
> >> it. Instead of getting the value I keep getting an XML fragment.
> >>
> >> An example should make this clearer:
> >>
> >> XML snippet:
> >>
> >> ...
> >> <RES SN="1" EN="10">
> >> <M>1410</M>
> >> ...
> >>
> >> XSD snippet:
> >>
> >> ...
> >> <xs:element name="RES">
> >> <xs:complexType>
> >> <xs:sequence>
> >> <xs:element ref="M"/>
> >> ...
> >>
> >> Java Code snippet:
> >>
> >> System.out.println(res.getM();
> >> System.out.println(res.getM().xmlText());
> >> System.out.println(res.getM().toString());
> >>
> >>
> >> All 3 println() statements produce the following output:
> >>
> >>
> >> <xml-fragment
> >>
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">1410</xml-fragm
> >> ent>
> >>
> >> Why is it printing <xml-fragment ...>? What should I do
> just to get
> >> the value (i.e. 1410)?
> >>
> >> Thanks in advance,
> >>
> >> MattC
> >> --
> >> View this message in context:
> >>
> http://www.nabble.com/XMLBeans-%3A-How-can-I-get-a-value-and-not-an-x
> >> ml-fragment--tp20521127p20521127.html
> >> Sent from the Xml Beans - User mailing list archive at Nabble.com.
> >>
> >>
> >>
> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: [EMAIL PROTECTED]
> >> For additional commands, e-mail: [EMAIL PROTECTED]
> >>
> >>
> >>
> >
> >
> ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> >
> >
> >
> _______________________________________________________
> Sulzer GmbH
> Geschaeftsfuehrer: Dr. Johann Sulzer, Hildegard Sulzer,
> Albert Euba, Hans-Dieter Panzer, Angelika Rudolph Sitz und
> Registergericht: Stuttgart HRB 7608
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]