Is an xsd pattern valid for decimal places?

We have a request to implement our response to a web service, so that the numbers xsd: decimal will be zero if it is not so long when it points to a pattern. I am wondering if this is a reasonable request, and if xsd: decimal is supposed to be used with such patterns. Here is the relevant part of xsd according to their specifications:

<xsd:simpleType> <xsd:restriction base="xsd:decimal"> <xsd:totalDigits value="14"/> <xsd:fractionDigits value="2"/> <xsd:pattern value="[\-+]?[0-9]{1,12}[.][0-9]{2}"/> </xsd:restriction> </xsd:simpleType> 

Thus, the Digits fraction is set to 2, which means that the accuracy can be no more than two digits. According to http://zvon.org/xxl/XMLSchemaTutorial/Output/ser_types_st2.html , it is also fine if there are lower digits (for example, for a number like 5.1)

But according to the pattern {2} there should always be 2 digits of shares.

We are developing a common application development platform and do not know what will use the decimal place in advance (currency, pH values, distances, etc.). This case comes from a specific project in which our platform is used, but usually we will not know what data is transmitted. We could decide to simply follow the WSDL in this regard, which claims to have 2 digits of digits. but our implementation should be very general.

It is not said that it is these numbers of digits that should be supplemented, or even that we should use instead of just leaving this decimal integer. Theoretically, we could select a pad with 5 until it matches the pattern. As far as I know, models are rarely used, and if they are used for things like passwords. The XSD specification is vague, so it would be useful if someone could shed some light on whether it is really using XSD, and if it makes sense for us to decide what needs to be imposed on 0.

+4
source share
2 answers

To be practical, my litmus test would have to examine this from the point of view of the technology stack directly related to it, or, even better, that is, the main one.

I can think of JAXB in Java or xsd / svcutil / etc.exe in .NET; A quick test of these fairly common tools against this fragment of the schema using a value of 1 will not produce the correct XML. This will allow developers to scramble all kinds of settings so that they work according to the XSD template. Large, high development and maintenance costs ...

The same would apply to XSLT; it will be necessary to manually format the output ... Bottom line, XSD templates are not used by the machine for "automatic" formatting ... I have yet to see such a thing ...

I also believe that such a requirement is unreasonable, and I personally believe that it should be regarded as antipattern when it comes to the description of exchange data. Since there is no absolute, it can be assumed that there should be an exception; I can’t think of anything, but I need to investigate the reason why you were presented with such a demand; Then I tried to find a solution that would not include this pattern ...

+2
source

In fact, it depends on the parameter of this decimal value.

XML is one of the most preferred for transporting and storing data that can have various data. Here I select two examples:

  • Data is the currency. Here, my advice is to get [0-9]*[.][0-9]{2} .. to help our client data recovery software, a way to fill in 0s has been developed.

  • The data are the pH value of the chemical, good. Here, one digit after the decimal point is required. [0-1][0-9][.][0-9]

So, it all depends on the object we are talking about. If it is really necessary, it would be unfair to force a template :)

+1
source

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


All Articles