XML-schema/validation: different separator for datatype double

我怕爱的太早我们不能终老 提交于 2019-12-17 19:52:53

问题


I changed the datatype of some parameters within my xsd file from string to their real type, in this case double. now I'm facing the problem that around here the comma is used as a separator and not the point as defined by the w3 (http://www.w3.org/TR/xmlschema-2/#double) causing erros all over during deserialization (C#, VS2008).

my question: Can I use the w3 schema for validation but with a different separator for double values?

thx for your help


回答1:


You cannot do that if you want to continue to use the XML Schema simple types. decimal and the types derived from it are locked down to using a period. As you say: the spec here.

If you want to use a comma as a separator, you need to define your own simple type, for example:

<xs:simpleType name="MyDecimal">
  <xs:restriction base="xs:string">
    <xs:pattern value="\d+(,\d+)?"/>
  </xs:restriction>
</xs:simpleType>

Before you do that, though, be careful; XML is a data storage format, not a presentation format. You might want to think about whether you sort this out after loading or during XSLT transformation, etc.



来源:https://stackoverflow.com/questions/2237593/xml-schema-validation-different-separator-for-datatype-double

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!