所需元素含量

发布于 2024-09-02 21:01:32 字数 578 浏览 2 评论 0原文

我正在尝试为这样的元素创建 xsd:

<ElementType attr1="a" attr2 ="b">mandatory_string</ElementType>

并且我想让 mandatory_string 成为必需的。我应该向此 xsd 添加什么:

<xs:complexType name="ElementType">
 <xs:simpleContent>
  <xs:extension base="xs:string">
   <xs:attribute name="attr1" type="StringLength1to2" use="required"/>
   <xs:attribute name="attr2" type="StringLength1to2" use="required"/>
  </xs:extension>
 </xs:simpleContent>
</xs:complexType>

目前是可选的。缺少什么?

I'm trying to create xsd for an element like this:

<ElementType attr1="a" attr2 ="b">mandatory_string</ElementType>

and I want to make the mandatory_string required. What should I add to this xsd:

<xs:complexType name="ElementType">
 <xs:simpleContent>
  <xs:extension base="xs:string">
   <xs:attribute name="attr1" type="StringLength1to2" use="required"/>
   <xs:attribute name="attr2" type="StringLength1to2" use="required"/>
  </xs:extension>
 </xs:simpleContent>
</xs:complexType>

Currently is optional. What's missing?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

只是我以为 2024-09-09 21:01:33

正如评论中提到的,我知道的唯一方法是使用“限制”,“模式”有限制:

<xs:simpleType name="orderidtype">
    <xs:restriction base="xs:string">
        <xs:pattern value="[0-9]{6}"/>
    </xs:restriction>
</xs:simpleType>

但我不确定这正是您正在寻找的。您是否想知道是否可以将整个标签设置为必需,或者仅将字符串本身设置为必需?如果只是字符串,您可以在上面的示例中使用正则表达式。

As mentioned in the comment the only way I know of is to use 'restriction's there is a restriction of 'pattern':

<xs:simpleType name="orderidtype">
    <xs:restriction base="xs:string">
        <xs:pattern value="[0-9]{6}"/>
    </xs:restriction>
</xs:simpleType>

I am not sure that is exactly what you are looking for though. Are you wondering if you can make the entire tag required, or just the string itself? If just the string you could just use a regex expression in the above example.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文