Jaxb 默认为无穷大

Jaxb default to infinity

我正在尝试使用 Jaxb 创建一个 XML 模式来表示数字 picker/spinner 的参数:最小值、最大值和步长。我希望最大默认为无穷大,最小为负无穷大,步长默认为 Double.MIN_VALUE.

无穷大和负无穷大都是有效的 xml 和 double 值,所以它们似乎应该是一种默认的方式。如果他们是 Double.MIN_VALUE 的捷径,而不仅仅是复制该数字,则可以加分。

目前我有:

  <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>

我得到:

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)
...

谢谢!

根据 w3.org INF 或 -INF 是可接受的值。没有提到 +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.

更新(归功于@Michael-Kay):

+INF becomes a valid value in XSD 1.1.

his answer