1

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!

yesennes
  • 1,147
  • 1
  • 10
  • 19

1 Answers1

2

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.

LMC
  • 10,453
  • 2
  • 27
  • 52
  • 1
    +INF becomes a valid value in XSD 1.1. – Michael Kay Sep 03 '21 at 21:18
  • @MichaelKay so it works depending on the Sax version? – LMC Sep 03 '21 at 21:22
  • 1
    Nothing to do with Sax -- it depends on the version of the XSD Schema specification supported by the XSD processor. JAXB is still on XSD 1.0. – Michael Kay Sep 03 '21 at 22:23
  • @MichaelKay what provides XSD processor implementation, Java jdk? Could you recommend a tutorial/doc to learn how all this relates together? Thanks :-) – LMC Sep 03 '21 at 22:52
  • 1
    I'm afraid I don't know whether JAXB has the capability to select a schema processor other than the one that comes with the JDK (which is XSD 1.0). You'll have to research that yourself. There are two XSD 1.1 processors available for Java users - Apache Xerces and Saxon-EE. – Michael Kay Sep 04 '21 at 14:15