Reputation: 3658
In the following XML, what is the alternative way to place a comment over the attributes of element?
<!-- I can comment here -->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/textView_ben"
<!-- Cannot place a comment here -->
android:layout_centerHorizontal="true"/>
Upvotes: 13
Views: 6421
Reputation: 319
Use triple forward slash ///
<remote name="test"
fetch="url" ///comment here
revision="21"
</remote>
Upvotes: 0
Reputation: 103
Indeed there are no "real" comments (ignored by the parser). But like in Python, where doc strings are commonly used for comments, you might simply use your own attributes as comments (and ignore them by yourself):
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/textView_ben" comment1="this id is used for ..."
android:layout_centerHorizontal="true" comment2="keep in mind, that ..."
/>
Upvotes: 0
Reputation: 1873
No, this isn't possible. Comments are not allowed in an XML open tag.
See How do I comment attributes inside an XML tag?
Upvotes: 17
Reputation: 111726
A comment can only appear before or after the start tag (regardless of whether it is an empty tag).
A comment may not appear within the start-tag of an XML element:
[40] STag ::= '<' Name (S Attribute)* S? '>'
Nor may a comment appear within an end-tag:
[44] EmptyElemTag ::= '<' Name (S Attribute)* S? '/>'
In general, per section 2.5 Comments:
[Definition: 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. ...]
Here is one way to document element attributes:
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/textView_ben"
android:layout_centerHorizontal="true"/>
<!--
android:id="@+id/textView_ben"
addresses defect #123
android:layout_centerHorizontal="true"
blah blah blah -->
Alternatively, such a comment may appear before the tag; it just cannot appear within a tag.
Upvotes: 1