attribute3="value3">

Is this a valid XML comment?

Is the code below valid XML?

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

</sometag>
+3
source share
3 answers

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

It says:

Comments can appear anywhere in the document outside of other markup; in addition, they may appear in a document type declaration in places permitted by the grammar.

And the grammar for the element’s start tag:

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

S Name Eq AttValue . 2 ( , ) Comment .

, NO.

+6
+3

No. Comments cannot appear in the middle of tags.

+1
source

Source: https://habr.com/ru/post/1757744/


All Articles