How do I comment attributes inside an XML tag?

Ntropy Nameless picture Ntropy Nameless · Oct 20, 2014 · Viewed 25.2k times · Source

Is it possible to comment one or several attributes inside an XML tag? Something like /* */ from C.

I have tried using <!-- -->, but it was unsuccessful.

<element
    attribute1="value1"
    attribute2="value2"
    <!-- attribute3="value3" (commented value) -->
>

Answer

Jeroen Mostert picture Jeroen Mostert · Oct 20, 2014

No, this isn't possible. Comments are not allowed in an XML open tag. Depending on your application, you might get away with "commenting out" the attributes by prefixing their names with "_", or you might not (if the XML is validated against a schema or all attributes are parsed). Because whitespace is allowed, and most editors support line operations, you can "comment" multiple attributes easily this way:

<element
   _attr1="value1"
   _attr2="value2"
   _attr3="value3"
>

But these attributes are still part of the document.