Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I comment attributes inside an XML tag?

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) --> > 
like image 530
Ntropy Nameless Avatar asked Oct 20 '14 08:10

Ntropy Nameless


People also ask

How do you comment text in XML?

An XML comment encountered outside the document type declaration is represented by the Comment value syntax element. It contains the comment text from the XML message. If the value of the element contains the character sequence --> , the sequence is replaced with the text --&gt; .

Does XML allow commenting elements?

Allows notes and other human readable comments to be included within an XML file. XML Parsers should ignore XML comments. Some constrains govern where comments may be placed with an XML file.

How do you comment and uncomment in XML?

To add comments in XML file, enclose the comment between `<! -- -->`. Shortcut key is Ctrl+shift+/. To uncomment in XML file, select the line/code which is commented and press Ctlr+shift+\.

Can comments be nested in XML?

No, the string -- is not permitted to appear within comments in XML. So the fact you have -- show up inside another comment is going to cause failures.


1 Answers

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.

like image 173
Jeroen Mostert Avatar answered Sep 29 '22 16:09

Jeroen Mostert