Does Javadoc have an equivalent to <![CDATA[ … ]]>?

后端 未结 4 862
心在旅途
心在旅途 2020-12-15 04:10

Unfortunately, there is no CDATA in HTML.

This is a pity, because it would be perfect for adding javadoc comments that include XML, so you don\'t have t

4条回答
  •  甜味超标
    2020-12-15 04:26

    I have tried quite a few solutions, none of which were very satisfactory for my needs. Doing the pre + @code (or @literal) tags will usually work:

     
     {@literal
     
       
         LOGICAL_INDEX_CONFIG
       
     }
     

    The trouble is, what if you have ${dollar_sign_variables} in your html? (and this is frequent if your documentation uses xml examples which rely on maven filtering). Say you have ${ITEM_INDEX_TO_LOGICAL}, Eclipse will render it like this:

    
      
         ITEM_INDEX_TO_LOGICAL
    
       }
    

    Ultimately, I had no choice but to stick to the html-escaping method (you can use this one) to get it to render propertly:

    This:

     <configFiles>
       <configFile>
         <type>${ITEM_INDEX_TO_LOGICAL}</type>
       </configFile>
     </configFiles>
    

    Renders like this:

     
       
         ${ITEM_INDEX_TO_LOGICAL}
       
     
    

    This will unfortunately put you into a position where you can't really understand the 'example xml' being documented unless you render the Javadoc. Fortunately eclipse can do this for you on the fly...

提交回复
热议问题