[xsd-users] Parsing an undefined floating point number

Boris Kolpackov boris at codesynthesis.com
Thu Feb 5 15:27:37 EST 2009


Hi,

Homer J S <js.homer at yahoo.com> writes:

> Hello, using XSD I parsed an object that contains the following 
> empty element (the missing value is supposed to be a float number):
> 
>     <md uom=""></md>

What is the definition for the 'md' element and its type in your
schema? Empty string is not a valid float representation in XML
Schema.


> then I simply serialized it to standard output, I got
> 
>     <md uom="">1.93164647928294e-317</md>
> 
> I got other values in additon to 1.93164647928294e-317. Can someone
> please suggest a way to detect if the float value I am trying to 
> retrieve (after parsing) is undefined.

One way would be to customize md's type. Let's assume you have the
following in your schema:

  <complexType name="md_type">
    <simpleContent>
      <extension base="float">
        <attribute name="uom" type="string"/>
      </extension>
    </simpleContent>
  </complexType>

  <element name="md" type="md_type"/>

You can customize the generated md_type C++ class to do three things.
You will want to add a member that indicates that the float value is
"undefined". You will also want to provide your own implementation
for the parsing c-tor that checks whether the float representation
is empty and set the "undefined" flag (you can still call the base
c-tor to handle the attribute and the float value parsing but then
check if the DOMElement's value is empty and if so set the "undefined"
flag). Finally, you will also want to override the serialization
operator so that it checks the "undefined" flag and if it's set,
writes an empty string instead of some bogus float value (again,
you can first call the base implementation and then clear the
DOMElement's value if the "undefined" flag is set).

For more information on type customization see the C++/Tree Mapping
Customization Guide:

http://wiki.codesynthesis.com/Tree/Customization_guide

The 'wildcard' example in the examples/cxx/tree/custom/ directory
does things that are very similar to what you will need to do.

Boris




More information about the xsd-users mailing list