XML 属性需要空值

标签 xml dtd

我已将属性“number”设置为#REQUIRED,但空值有效吗?

DTD:

<!ATTLIST person number CDATA #REQUIRED>

XML:

<person number="" />

最佳答案

是的,空值足以满足 XML 属性的#REQUIRED 约束。属性的值是无关紧要的;只需要属性的存在即可:

Validity constraint: Required Attribute

If the default declaration is the keyword #REQUIRED, then the attribute must be specified for all elements of the type in the attribute-list declaration.

关于XML 属性需要空值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44999039/

相关文章:

c# - XmlReader 和 NodeTypes

xml - 子节点中的命名空间为空

java - 从 DTD 生成 XML 绑定(bind)代码的最佳方法是什么?

xml - XML 属性可以有空格吗?

Java设计问题: Is this a good design?

c# - 根据KeyWord从XML中提取一个节点

java - 如何在log4j.xml中使用DTD ENTITY外部引用

将xml转换为dtd的php脚本

sql-server - 使用 "FOR XML PATH"时如何避免编码?

java - 在 Java 中引用本地 DTD