XML xs: int hexadecimal value

I want to save a number in an XML file with a type or another simple integer type, but allow the user to enter the number in hexadecimal format. Does the XML standard provide this because I cannot find anything relevant?

For example, if the XSD says:

<xs:element name="value" type="xs:integer" use="required" /> 

then I want XML to be able to say:

 <value>0xFF00FF</value> 

or to indicate a hexadecimal value.

Obviously, I can try, but this proves support in only one specific implementation, and not in the standard. I am not particularly interested in whether XML retention will lose.

+6
source share
4 answers

I do not think so. xs:integer is a derived / subset of type xs:decimal , whose representation is defined as

decimal has a lexical representation consisting of a finite length of decimal digits (# x30- # x39), separated by a period as a decimal indicator. A valid leading character is allowed. If the character is omitted, a "+" is assumed. Leading and trailing zeros are optional. If the fractional part is zero, the period and the next zero (es) can be omitted. For example: -1.23, 12678967.543233, +100000.00, 210.

You can remove 0x and set it to hexBinary, although you lose the semantic number.

+4
source

Id uses the regular expression in the <xs:pattern> element.

 <xs:element name="value" use="required"> <xs:simpleType> <xs:restriction base="xs:string"> <xs:pattern value="0x[0-9A-Fa-f]+|[0-9]+"/> </xs:restriction> </xs:simpleType> </xs:element> 

This allows you to store both decimal and hexadecimal numbers (with the mandatory prefix 0x ). However, you will need to process it specifically, converting the string to a number.

+4
source

XSD does not allow this.

But XSD 1.1 resolves faces defined by the implementation, including prelexic faces, and Saxon uses this freedom to provide the saxon: the preprocess phase described here:

http://www.saxonica.com/documentation/#!schema-processing/extensions11/preprocess

This will allow you to accept the hexadecimal notation as a lexical representation of the integer type. The only drawback (possibly a big one!) Is that it will only work with Saxon.

+2
source

I needed it myself and got here.

Here is a 32-bit unsigned integer type that will allow you to enter a value in both hexadecimal and decimal.

 <xs:simpleType name="U32BitHexInt"> <xs:union memberTypes="xs:unsignedInt"> <xs:simpleType> <xs:restriction base="xs:token"> <xs:pattern value="0x[0-9A-Fa-f]{8}"/> </xs:restriction> </xs:simpleType> </xs:union> </xs:simpleType> 
+1
source

Source: https://habr.com/ru/post/921871/


All Articles