Question

Is the code below valid XML?

<sometag
    attribute1="value1"
    <!-- attribute2="value2" -->
    attribute3="value3">

</sometag>
Was it helpful?

Solution

Questions like this are best answered by referring to the relevant specifications. In this case the Extended Markup Language (XML) 1.1 specification.

This says:

Comments may appear anywhere in a document outside other markup; in addition, they may appear within the document type declaration at places allowed by the grammar.

And the grammar for an element start tag is:

[40]    STag       ::=      '<' Name (S  Attribute)* S? '>'
[41]    Attribute  ::=      Name Eq AttValue

where the non-terminal symbols S Name Eq and AttValue are defined elsewhere. These 2 productions (and the others which I haven't included here) do not allow the Comment non-terminal symbol in this context.

So that is a definitive NO.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top