2010-09-09 76 views
0

我使用的xsd:schema将用于生成所需的xml,我在xsd:schema中有一个标题字段。如何验证xsd:schema中的textfield元素

我想从xsd:schema验证它,只有当用户尝试将超过,1个字符的值都会生成错误。

下面是我XSD的部分:模式

<xsd:sequence> 
    <xsd:element name="Title" minOccurs="0" maxOccurs="1" type="xsd:normalizedString"/>   
    <xsd:element name="City" minOccurs="0" maxOccurs="1" type="tcmi:SimpleLink"> 
     <xsd:annotation> 
      <xsd:appinfo> 
       <tcm:linktype>ComponentLink</tcm:linktype> 
       <tcm:AllowMultimediaLinks>false</tcm:AllowMultimediaLinks> 
       <tcm:AllowedTargetSchemas> 
        <tcm:TargetSchema xlink:href="tcm:227-190428-8" xlink:title="City"/> 
       </tcm:AllowedTargetSchemas> 
      </xsd:appinfo> 
     </xsd:annotation> 
    </xsd:element> 
    <xsd:element name="FlightLinkText" minOccurs="0" maxOccurs="1" type="xsd:normalizedString"/>     
</xsd:sequence> 

我的手段,我们可以验证它<xsd:element name="Title" minOccurs="0" maxOccurs="1" type="xsd:normalizedString"/>

请建议!

回答

0

你有没有尝试过这样的:

<xsd:element name="Title" minOccurs="0" maxOccurs="1"> 
    <xsd:simpleType> 
    <xsd:restriction base="xsd:normalizedString"> 
     <xsd:maxLength value="10"/> 
    </xsd:restriction> 
    </xsd:simpleType> 
</xsd:element> 
+0

感谢我们能期望的错误信息被voiliated时!像“你不能有超过10个字符的标题” – 2010-09-09 05:16:57

+0

我不认为可以直接在你的XSD文件中定义它,如果这是你的意思。当验证程序识别标题太长并显示相应的错误消息时,您的代码必须捕获异常。你使用哪种编程语言? – uloBasEI 2010-09-09 18:47:50