developer tip

XML에서 태그 블록을 주석 처리하려면 어떻게합니까?

copycodes 2020. 9. 29. 07:56
반응형

XML에서 태그 블록을 주석 처리하려면 어떻게합니까?


XML에서 태그 블록을 주석 처리하려면 어떻게합니까?

Ie <staticText>아래 코드에서 어떻게 주석을 달 수 있습니까?

  <detail>
    <band height="20">
      <staticText>
        <reportElement x="180" y="0" width="200" height="20"/>
        <text><![CDATA[Hello World!]]></text>
      </staticText>
    </band>
  </detail>

사용할 수는 <!-- staticText-->있지만 //Java 및 C에서와 같이 단일 태그에 대해서만 /** comment **/사용할 수 있습니다. Java 및 C에서 사용할 수있는 방법과 같은 것을 더 원 하므로 더 긴 XML 코드 블록을 주석 처리 할 수 ​​있습니다.


여러 줄에 걸쳐 해당 스타일의 주석을 사용할 수 있습니다 (HTML에도 있음).

<detail>
    <band height="20">
    <!--
      Hello,
         I am a multi-line XML comment
         <staticText>
            <reportElement x="180" y="0" width="200" height="20"/>
            <text><![CDATA[Hello World!]]></text>
          </staticText>
      -->
     </band>
</detail>

존재하지 않는 처리 명령으로 텍스트를 래핑 할 수 있습니다. 예 :

<detail>
<?ignore
  <band height="20">
    <staticText>
      <reportElement x="180" y="0" width="200" height="20"/>
      <text><![CDATA[Hello World!]]></text>
    </staticText>
  </band>
?>
</detail>

중첩 된 처리 명령어는 허용되지 않으며 '?>'는 처리 명령어를 종료합니다 ( http://www.w3.org/TR/REC-xml/#sec-pi 참조 ).


If you ask, because you got errors with the <!-- --> syntax, it's most likely the CDATA section (and there the ]]> part), that then lies in the middle of the comment. It should not make a difference, but ideal and real world can be quite a bit apart, sometimes (especially when it comes to XML processing).

Try to change the ]]>, too:

  <!--detail>
    <band height="20">
      <staticText>
        <reportElement x="180" y="0" width="200" height="20"/>
        <text><![CDATA[Hello World!]--><!--]></text>
      </staticText>
    </band>
  </detail-->

Another thing, that comes to mind: If the content of your XML somewhere contains two hyphens, the comment immediately ends there:

<!-- <a> This is strange -- but true!</a> -->
--------------------------^ comment ends here

That's quite a common pitfall. It's inherited from the way SGML handles comments. (Read the XML spec on this topic)


Actually, you can use the <!--...--> format with multi-lines or tags:

<!--
  ...
  ...
  ...
-->

Here for commenting we have to write like below:

<!-- Your comment here -->

Shortcuts for IntelliJ Idea and Eclipse

For Windows & Linux:

Shortcut for Commenting a single line:

Ctrl + /

Shortcut for Commenting multiple lines:

Ctrl + Shift + /

For Mac:

Shortcut for Commenting a single line:

cmnd + /

Shortcut for Commenting multiple lines:

cmnd + Shift + /

One thing you have to keep in mind that, you can't comment an attribute of an XML tag. For Example:

<TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    <!--android:text="Hello.."-->
    android:textStyle="bold" />

Here, TextView is a XML Tag and text is an attribute of that tag. You can't comment attributes of an XML Tag. You have to comment the full XML Tag. For Example:

<!--<TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="Hello.."
    android:textStyle="bold" />-->

You can easily comment out the data using this:

<!-- 
 <data>
        <data-field1></data-field1>
        <data-field2></data-field2>
        <data-field3></data-field3>
 </data>
-->

method of commenting in xml.

참고URL : https://stackoverflow.com/questions/2757396/how-do-i-comment-out-a-block-of-tags-in-xml

반응형