如何通过 xsd 限制元素为非空 [英] How to restrict an element to be non-empty through xsd

查看:45
本文介绍了如何通过 xsd 限制元素为非空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用 xsd 文件将 xml 文件中的元素限制为非空.我可以强制元素只包含 CDATA 部分吗?

I need to restrict the elements in xml file to be non empty using xsd files. Can I force the elements to contain only CDATA sections?

推荐答案

您拥有的唯一工具是 xs:string 模式限制,如下所示.CDATA 只是使用实体引用进行转义的替代方法.您应该在您的模式中使用实体引用.

The only tool you have is the xs:string pattern restriction as in below. CDATA is just an alternative to escaping with entity references. You should use entity references in your pattern.

<simpleType name="NewType2">
    <restriction base="string">
        <minLength value="5"></minLength>
        <maxLength value="30"></maxLength>
        <pattern value="(&lt;html&gt;).*(&lt;/html&gt;)"></pattern>
    </restriction>
</simpleType>

这篇关于如何通过 xsd 限制元素为非空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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