XML 架构 - 使空元素无效
应该很简单,但我在任何地方都找不到这方面的任何信息。我想要一些简单的元素,因此如果某些元素为空,则 XML 无效。我尝试过使用 nillable 属性,但这不起作用。我必须对所需的字符数添加限制,然后删除空格才能使其正常工作,但这似乎很冗长,我是否遗漏了一些东西?
例如。
<xsd:element name="productImageURL">
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:minLength value="1"/>
<xsd:maxLength value="450"/>
<xsd:whiteSpace value="collapse"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
Should be simple but I cannot find any information on this anywhere. I want to make some simple elements required, therefore invalidate the XML if some of the elements are empty. I have tried using the nillable attribute but this does not work. I have had to add limitations to the number of characters needed and then remove white space to get this working but it seems really lon winded, am I misssing something?
eg.
<xsd:element name="productImageURL">
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:minLength value="1"/>
<xsd:maxLength value="450"/>
<xsd:whiteSpace value="collapse"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
XML 模式就是这样。另一种选择可能是使用 xsd:pattern 方面...但可读性比您所做的方式要好得多;大多数人很难阅读正则表达式等模式......
It is the way it is with the XML Schema. Another option could be to use the xsd:pattern facet... Readability though is much better the way you've done it; most people struggle reading patterns such as regular expressions...