Is an xml attribute without a value, valid?

北城以北 提交于 2019-11-26 11:24:37

问题


I want to have an XML attribute without any value, which simply has one meaning when it exists or does not exist.

Is that valid?


回答1:


An attribute must be specified with the following syntax:

Name Eq AttValue

where Name is a legal XML name, Eq is = optionally preceded or followed by whitespace, and AttValue is a legal attribute value.

This definition is true for both XML 1.0 and XML 1.1.

If you are trying to specify an attribute as below:

<car owned/>

then no, that is not valid. If you are trying to specify it this way:

<car owned=""/>

then yes, that is valid.




回答2:


No.

Boolean attributes in XML are of the form foo="foo".

Even in SGML, you must provide the value, (it is the name, = and quotes that you can omit, which is why you have things like <select multiple> in HTML).




回答3:


Yes. You can have an attribute whose only permitted value is the empty string, "". I't not sure it's good design, though: I would normally suggest a boolean attribute with values true/false, and a default value of false.



来源:https://stackoverflow.com/questions/6926442/is-an-xml-attribute-without-a-value-valid

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!