yesennes
yesennes

Reputation: 1267

Jaxb default to infinity

I'm trying to make a XML Schema with Jaxb to represent the parameters for a number picker/spinner: min, max and step. I want to have max default to infinity, min to negative infinity, and step default to Double.MIN_VALUE.

Both infinity and negative infinity are valid xml and double values, so it seems like their should be a way to have it default to them. Bonus points if their a shortcut to Double.MIN_VALUE other than just copying that number.

Currently I have:

  <xsd:element name="NumericParameter">
    <xsd:complexType>
      <xsd:complexContent>
        <xsd:extension base="batsignal:DetectorParameter" >
          <xsd:sequence>
            <xsd:element name="min" type="xsd:double" default="-INF"/>
            <xsd:element name="max" type="xsd:double" default="+INF" />
            <xsd:element name="step" type="xsd:double" default="0x0.0000000000001P-1022" />
          </xsd:sequence>
        </xsd:extension>
      </xsd:complexContent>
    </xsd:complexType>
  </xsd:element>

And I get:

org.xml.sax.SAXParseException; lineNumber: 173; columnNumber: 72; e-props-correct.2: Invalid value constraint value '+INF' in element 'max'.
    at java.xml/com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:204)
    at java.xml/com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(ErrorHandlerWrapper.java:135)
    at java.xml/com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:396)
    at java.xml/com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDHandler.reportSchemaErr(XSDHandler.java:4214)
...

Thanks!

Upvotes: 1

Views: 133

Answers (1)

LMC
LMC

Reputation: 12662

According to w3.org INF or -INF are accepted values. No mention of +INF.

The special values positive and negative infinity and not-a-number have lexical representations INF, -INF and NaN, respectively. Lexical representations for zero may take a positive or negative sign.

For example, -1E4, 1267.43233E12, 12.78e-2, 12 , -0, 0 and INF are all legal literals for double.

UPDATE (credit to @Michael-Kay):

+INF becomes a valid value in XSD 1.1.

See his answer.

Upvotes: 2

Related Questions