The use of special symbols in the xml file of Mybatis or Mybatis-Plus framework (<, <=, >, >=, &,', ")

The use of special symbols in the xml file of Mybatis or Mybatis-Plus framework (<, <=, >, >=, &,', ")


In Mybatis’s xml file, many special symbols cannot be used directly and need to use entity references. If a character like "<" is placed in the XML document, then this document will generate an error because the parser will It is interpreted as the beginning of a new element.

Original symbol, entity reference, CDATA comparison table

Original symbol Entity reference CDATA Description
< &lt; <![CDATA[ < ]]> Less than
<= &lt;= <![CDATA[ <= ]]> Less than or equal to
> &gt; <![CDATA[ > ]]> more than the
>= &gt;= <![CDATA[ >= ]]> greater or equal to
& &amp; <![CDATA[ & ]]> And sign
&apos; <![CDATA[ ' ]]> Ellipsis
" &quot; <![CDATA[ " ]]> quotation marks

Explanation

Why can't special symbols be used in xml files

"<" will produce an error because the parser will interpret this character as the beginning of a new element.
">" will produce an error because the parser will interpret this character as the end of a new element.
"&" will also produce an error, because the parser will interpret the character as the beginning of a character entity.

Notes on the CDATA section:

The term CDATA refers to text data (Unparsed Character Data) that should not be parsed by an XML parser.
Everything in the CDATA section will be ignored by the parser.
The CDATA part starts with "<![CDATA[" and ends with "]]>".
The CDATA part cannot contain the string "]]>". Nested CDATA sections are also not allowed.
The "]]>" marking the end of the CDATA part cannot contain spaces or line breaks.

Guess you like

Origin blog.csdn.net/weixin_39157014/article/details/109745110