开发者

XML Schema - make empty elements invalid

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>


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...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜