You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@xmlbeans.apache.org by Radu Preotiuc-Pietro <ra...@oracle.com> on 2009/01/06 19:34:08 UTC

RE: XMLBeans : How can I get a value and not an xml fragment?

Hello,

I don't think XMLBeans has what you want. How is your sort defined if one element has "12" as a String value and another has "12" as an integer? .getStringValue() gives you an uniform way of treating the contents as Strings, which you can always do, but if you want to treat the content as a typed value, you need to use XmlObject.schemaType() and the appropriate getter. Usually, working with Objects in the abstract is not very useful.

Radu 

> -----Original Message-----
> From: Siegfried Baiz [mailto:baiz@sulzer.de] 
> Sent: Friday, December 19, 2008 9:54 AM
> To: user@xmlbeans.apache.org
> Subject: Re: XMLBeans : How can I get a value and not an xml fragment?
> 
> Hi Radu,
> 
> thanks for your help. I forgot to work out my need for the 
> typed values:
> Given an array of XmlObjects, I am supposed to deliver a 
> sorted list of the distinct values.
> With your hint my code actually looks like this:
> 
> Set extractDistinctValues(XmlObject[] xoArr) throws 
> .CompareFailedException... {
> 
>   SortedSet result = new TreeSet();
>   
>   for (XmlObject xo: xoArr){
> 
>     if (xo instanceof org.apache.xmlbeans.impl.values.XmlObjectBase){
>         result.add(((XmlObjectBase)xo).getObjectValue()));
>     } else if (xo instanceof XmlAnySimpleType)
>     	result.add(((XmlAnySimpleType) xo).getStringValue());
>     } else{
>         // trying to extract textValue from Cursor	
>         result.add(getTextValue(xo.newCursor())); // dispose 
> Cursor inside!
>     }
> 
>   }
>   
>   return result;	
> 
> }
> 
> If I skipped the first if-closure with its use of 
> (XmlObjectBase)xo).getObjectValue(),
> sorting would be done on Strings, even if xoArr contains 
> Integer-Values only.
> So what I'm actually looking for, would be 
> (XmlAnySimpleType)xo).getObjectValue().
> Is there something like that?
> 
> Thanks in advance,
> 
> Siggi B.
> 
> 
> 
> Radu Preotiuc-Pietro wrote:
> > The correct way to do it would be:
> >
> > if (xo instanceof XmlAnySimpleType)
> >     return ((XmlAnySimpleType) xo).getStringValue();
> >
> > Radu
> >   
> _______________________________________________________
> 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: user-unsubscribe@xmlbeans.apache.org
> For additional commands, e-mail: user-help@xmlbeans.apache.org
> 
> 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: user-help@xmlbeans.apache.org