开发者

Is this a valid XML comment?

Is the code below valid XML?

<sometag
    attribute1="value1"
    <!--开发者_如何转开发 attribute2="value2" -->
    attribute3="value3">

</sometag>


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.


From the spec:

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.

No.


No. Comments cannot appear in the middle of tags.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜