The content contained by
This tag is used in xml documents, let's take a look at the use of escape characters. We know that in xml, characters such as
When read by the program, the parser will automatically convert these entities back to
In any case, the characters before escaping and the characters after escaping will be parsed by the xml parser. For convenience , it is used
(1) This part cannot contain any more
(2) Nesting is not allowed;
(3)
Finally, let's talk about
Yes, their functions are the same, but the application scenarios and requirements are slightly different:
(1) It is
(2)
(3)
<![CDATA[]]>
this tag will be represented as
plain text
, i.e.
<![CDATA[<]]>
text content
“<”
.
This tag is used in xml documents, let's take a look at the use of escape characters. We know that in xml, characters such as
”<”
,
”>”
,
”&”
etc. cannot be stored directly, otherwise an
error will be reported during the xml syntax check
. If you want to use these symbols in xml, you must escape them as entities, such as
”<”
,
”>”
,
”&”
, so that you can save them into the xml document.
When read by the program, the parser will automatically convert these entities back to
”<”
,
”>”
,
”&”
. For example:
The above writing method will report an error, it should be written like this : It is worth noting that: (1) There must be no spaces between escape sequence characters; (2) The escape sequence must end with ";"; (3) Separate The occurrence of "&" is not considered to be the beginning of an escape; (4) case-sensitive. In XML, the characters that need to be escaped are: (1)& (2)< (3)> (4)" (5)' But strictly speaking, only "<" and "&" are illegal in XML , the other three can exist legally, but it is a good practice to escape them all.
<age> age < 30 </age>
<age> age < 30 </age>
&
<
>
"
'
In any case, the characters before escaping and the characters after escaping will be parsed by the xml parser. For convenience , it is used
<![CDATA[]]>
to include content that is not parsed by the xml parser. But it should be noted that:
(1) This part cannot contain any more
”]]>”
;
(2) Nesting is not allowed;
(3)
”]]>”
This part cannot contain spaces or newlines.
Finally, let's talk about
<![CDATA[]]>
the relationship with xml transfer characters. Does the two seem to have duplicate functions?
Yes, their functions are the same, but the application scenarios and requirements are slightly different:
(1) It is
<![CDATA[]]>
not applicable to all situations, but escape characters are OK;
(2)
<![CDATA[]]>
It is verbose for short strings, and for long strings, escape characters are written. It is less readable;
(3)
<![CDATA[]]>
means that the xml parser ignores parsing, so it is faster.