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?
Empty XML Elements An element with no content is said to be empty. The two forms produce identical results in XML software (Readers, Parsers, Browsers). Empty elements can have attributes.
Defining XML Attributes An Attribute can appear 0 or 1 times within a given element in the XML document. Attributes are either optional or mandatory (by default they are optional). The "use" property in the XSD definition is used to specify if the attribute is optional or mandatory.
So, you can't have: the same character that opens/closes the attribute value (either ' or " ) a naked ampersand ( & must be & ) a left angle bracket ( < must be < )
XML elements can have attributes in name/value pairs; however, the attribute value must always be quoted. In the incorrect document, the date attribute in the note element is not quoted.
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.
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With