Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is an xml attribute without a value, valid?

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?

like image 233
Andreas Avatar asked Aug 03 '11 12:08

Andreas


People also ask

Can XML attributes be empty?

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.

Are XML attributes optional?

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.

Which of the character is not allowed in XML attribute?

So, you can't have: the same character that opens/closes the attribute value (either ' or " ) a naked ampersand ( & must be &amp; ) a left angle bracket ( < must be &lt; )

Is XML attributes must be quoted?

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.


2 Answers

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.

like image 167
Dave DuPlantis Avatar answered Sep 19 '22 20:09

Dave DuPlantis


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).

like image 35
Quentin Avatar answered Sep 20 '22 20:09

Quentin