我可以在DTD模式中使用正则表达式吗?

发布于 2025-01-27 16:19:59 字数 124 浏览 4 评论 0原文

我想强制执行XML元素必须包含ISBN代码。因此,我需要您的典型模式“ [0-9] {3} - [0-9] {3} ......

在DTD模式中可以实现吗?我读过,您不能将DTD与正则表达式结合在一起,但我不太确定。

I want to enforce that an XML element has to contain an ISBN code. Therefore, I need your typical pattern "[0-9]{3}-[0-9]{3}......".

Could that be achieved in a DTD schema? I've read you can't combine a DTD with regular expressions, but I'm not so sure.

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

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

发布评论

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

评论(1

秋千易 2025-02-03 16:19:59

不,您无法用DTD定义正则表格。

您可以执行带有XSD schemas 的正等式模式。

<xsd:simpleType name="SSN">
    <xsd:restriction base="xsd:token">
        <xsd:pattern value="[0-9]{3}-[0-9]{2}-[0-9]{4}"/>
    </xsd:restriction>
</xsd:simpleType>

另一个选项是应用某种其他验证,例如 schematron

No, you can't define regex patterns with DTD.

You can enforce regex patterns with XSD schemas.

<xsd:simpleType name="SSN">
    <xsd:restriction base="xsd:token">
        <xsd:pattern value="[0-9]{3}-[0-9]{2}-[0-9]{4}"/>
    </xsd:restriction>
</xsd:simpleType>

Another option is applying some sort of other validation, such as Schematron.

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