带有前导零的 XML 整数元素
我有一个 XML 文件,其中有一个整数类型的元素,但它有前导零。在发送 XML 之前,我可以在 xml 文件中看到该整数是例如 001234 ...但是在处理时,因为它应该是一个整数,所以前导零被删除。
xml 或 xsd 中有没有办法指定该整数的长度始终为 6 个字符? (在我告诉接收 xml 的人更改类型以在最后进行转换之前)
谢谢,
I have an XML file with an element that is of integer type but it has leading zeros. Before I send the XML off I can see in the xml file that the integer is e.g. 001234 ...but when getting processed as it's meant to be an integer the leading zeros are removed.
Is there a way in the xml or xsd to specify that this integer is always 6 characters in length? (Before I tell at the people who are receiving the xml to change type to convert at their end)
Thanks,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将类型声明为 xs:integer 告诉每个人前导零并不重要,即 0012 和 12 可以互换且等效,因为这是整数含义的一部分。您可以使用模式方面将长度限制为 6 位数字,但您会让自己陷入混乱,因为例如,如果您通过模式感知处理器进行身份转换,则前导零可能会丢失。
如果前导零确实很重要(例如,在电话号码中),则不应将其键入为整数,而应键入与模式 \d+ 匹配的字符串。
Declaring the type as xs:integer is telling everyone that leading zeros are not significant, i.e. that 0012 and 12 are interchangeable and equivalent, because that is part of what it means to be an integer. You can use a pattern facet to restrict the length to 6 digits, but you will get yourself into a mess, because for example if you do an identity transform through a schema-aware processor then the leading zeros are likely to be lost.
If leading zeroes really are significant (as in a phone number, for example), then it shouldn't be typed as an integer, but as a string matching the pattern \d+.
是的,您应该能够在架构中使用 decimal 类型。
Yes, you should be able to use the decimal type in your schema.