You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@xmlbeans.apache.org by Reid Pinchback <re...@yahoo.com> on 2005/11/20 18:54:35 UTC

user-defined value types

Hi all,

I've got something I'm trying to figure out
how to do in XmlBeans.  It is a situation
where I can't control the format of the
XML documents.  The product I'm working on
already exists so I'm stuck with conforming
to any legacy data oddities.

In the XML I have to parse or generate,
any given XML element text body value 
has a natural java type equivalence, but
their format is such that out-of-the-box 
types like "xs:float" don't seem to be of
much use to me.  

As an example I'll use floats, although 
in reality I'm dealing with floats, 
integers, currencies, dates, times, 
booleans; all with similar format 
challenges.  Also, for both labour
and performance reasons I'd rather 
not have to do an XSLT transform of 
every doc before or after using 
XmlBeans.

Consider XML like the following:

  <myDoc>
    <myVal>10F999</myVal>
  </myDoc>

Where "10F999" is supposed to be 
the textual representation of the 
floating-point number we would 
normally see as "10.999" in Java.
Odd to look at, but you could easily
create a java.text.Format 
implementation that could parse
these strings into floats, and
format floats into these strings.

Creating an xsd element definition for
myVal as a string is obvious enough:

  <xs:element name='myVal' 
              type='xs:string'/>

but that isn't particularly useful,
because "myVal" is a float, and I
want the Java code to work with the
semantic datatype that makes sense.
Having to traverse the whole object
tree and continually convert back and
forth from string to float and vice
versa is going to be a real pain.

Because of the odd data format, I
can't use something like:

  <xs:element name='myVal' 
              type='xs:float'/>

I suspect I need some way of
specifying my own type so that with
XmlBeans I end up with an XmlObject
classes generated that use my own
choice of formatter so that the
parse and save methods do the right
thing.

Being new to XmlBeans, I don't see
any way of doing this.

Any help would be appreciated.

  Reid



		
__________________________________ 
Start your day with Yahoo! - Make it your home page! 
http://www.yahoo.com/r/hs

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