如果 DTD 中存在属性,如何验证该属性不为空?
我有一个属性:
preprocessFile CDATA #IMPLIED
我希望此属性为:
- 如果存在,则允许不存在
- ,非空字符串
如何在 DTD 中表达此属性?为了尽量减少争论,请假设我了解 rng/xsd 并且无法将它们用于此特定任务。
I have an attribute:
preprocessFile CDATA #IMPLIED
I want this attribute to be:
- allowed to be absent
- if present, a non-empty string
How can I express this in a DTD? For the sake of minimizing argument, please assume that I know about rng/xsd and cannot use them for this particular task.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
无法使用 XML DTD 来验证属性是否存在,并且该属性不能为空。
以下是您的选项:
preprocessFile CDATA "novalueprovided"
无论哪种情况,您都可以在 XML 解析代码中强制属性“不存在或不为空”。
There is no way using an XML DTD to validate that if an attribute is present it must not be empty.
Here are your options:
preprocessFile CDATA "novalueprovided"
In either case, you can enforce the attribute to be "absent or not empty if present" in your XML parsing code.
我同意 DwB 的观点,即这超出了 DTD,即使有上面的建议,它仍然允许显式指定空字符串。但由于 DTD 也不允许任何数据类型规范,因此这符合图片,因为您不仅需要字符串数据类型,还需要长度限制。当然,任何真正的模式语言,如 RNG (RelaxNG) 或 XML:Schema 都可以轻松支持这样的检查,这里给出了 RNG:
I agree with DwB, that this is beyond DTD, which even with the suggestions above would still allow to specify the empty string explicitly. But since DTD also permits no data type specifications, this fits within the picture, since your are not only requiring the string data type but additionally a length restriction. Of course any real schema language like RNG (RelaxNG) or XML:Schema easily supports a check like this, RNG given here: