XSD:如何限制字符串类型属性中的字符数? [英] XSD: how to restrict number of characters in string type attribute?

查看:25
本文介绍了XSD:如何限制字符串类型属性中的字符数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个关于在我的 xml 架构 (xsd) 中添加限制的问题.我有一个复杂的类型:

I have a question regarding adding restriction in my xml schema(xsd). I have a complex-type like:

<xsd:complexType name="xxx">
   <xsd:attribute/>
   .....
</xsd:complexType>

我在这个复杂类型中有很多属性,其中很少有字符串类型.现在我希望将这些字符串类型属性限制为 y no.字符数,如何添加此限制?

I have many attributes in this complex-type, and few of them are of string type. Now I want those string type attributes to be restricted to y no. of chars, how do I add this restriction?

谢谢!-安库什

推荐答案

你需要像这样创建一个简单的类型:

You need to create a simple type like so:

  <xs:simpleType name="LimitedString">
    <xs:restriction base="xs:string">
      <xs:maxLength value="50" />
    </xs:restriction>
  </xs:simpleType>

然后在你的架构中使用这个新类型:

and then use this new type in your schema:

  <xs:complexType name="test">
    <xs:sequence>
      <xs:element name="abc" type="xs:String" />
    </xs:sequence>
    <xs:attribute type="LimitedString" name="myattr" />
  </xs:complexType>

马克

这篇关于XSD:如何限制字符串类型属性中的字符数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆