An XML Element can contain 0-n XML Attributes. Attributes are contained within the start tag and must be unique within it.
In practice this means an XML element can look like these examples
<MyElement myAttribute="attribute value"/>
<MyElement myAttribute="attribute value">...</MyElement>
<MyElement myAttribute='attribute value'>...</MyElement>
<MyElement myAttribute1="attribute value" myAttribute2="attribute value">...</MyElement>
Attributes can be associated with a namespace. Namespaces allow data to be broken up, it also allows a parser to ignore parts of a document it was not designed to deal with.
Namespaces are applied to an attribute using a namespace prefix. The prefix must be defined within the containing element (or any of its contianing parent elements back to the document element).
<RootElm xmlns:nsA="MyNamespace"> <SubElm> <MyElement nsA:myAttribute1="attribute value" myAttribute2="attribute value">...</MyElement> </SubElm> </RootElm>
Typically attributes that have no namespace prefix, are deemed to belong to the containing elements namespace. But this is a complex area, have a look at XSD Namespace rules.
If you put control characters (",',&) into an attributes value, this would cause the parser to miss understand the resulting text, so in order for the parser to operate correctly these control characters need to be escaped, see Escaping XML Data.
You can not place a comment inside an attribute value.
When an XML Parser reads an XML Attribute it is supposed to do some processing to normalize the whitespace within the attribute value.
When an XML Parser reads an XML Attribute the XML Spec says it should normalize the whitespace it contains (this means replacing all whitespace characters with spaces).
3.3.3 Attribute-Value Normalization
Before the value of an attribute is passed to the application or checked for validity, the XML processor MUST normalize the attribute value by applying the algorithm below, or by using some other method such that the value passed to the application is the same as that produced by the algorithm.
When the XML document is ready in conjunction with a DTD further rules come into play.
3.3.3 Attribute-Value Normalization
If the attribute type is not CDATA, then the XML processor MUST further process the normalized attribute value by discarding any leading and trailing space (#x20) characters, and by replacing sequences of space (#x20) characters by a single space (#x20) character.
When the XML document is read in conjunction with an XSD schema, a number of additional rules apply.
If the Attributes data type is "xs:string" no further whitespace normalization is performed.
If the Attributes data type is "xs:normalisedString" the xsd "Replace" rule is applied (which should already have been applied as part of the XML attribute normalization).
Attributes of any other data type are normalized using the xsd "Collapse" rule.
If a custom data type is defined within the XSD that is based on "xs:string" or "xs:normalisedString", the the XSD can change the whitespace rules for that data type using the whitespace facet.
Note not all XML parsers correctly implement the whitespace normalization rules.
The syntax for an attribute is described by the W3C as using EBNF as follows.
[10] AttValue ::= '"' ([^<&"] | Reference)* '"'
| "'" ([^<&'] | Reference)* "'" [40] STag ::= '<' Name (S Attribute)* S? '>' [41] Attribute ::= Name Eq AttValue [44] EmptyElemTag ::= '<' Name (S Attribute)* S? '/>'