问题
The following EBNF rule expressed as
CharData ::= [^<&]* - ([^<&]* ']]>' [^<&]*)
is really hard for me to understand. Can someone give a few examples of valid and invalid strings. A brief explanation of the what is being expressed in the rule would also be very helpful. Although perhaps asking a little much. It would also be ultra nice if you have an interesting snippet of c++ code lying around that'll help catch this occurrence.
回答1:
The EBNF production for CharData,
[14] CharData ::= [^<&]* - ([^<&]* ']]>' [^<&]*)
means that XML character data can consist of any characters except
<
, which begins markup (tags, comments, XML declarations, CDATA sections, and PIs)&
, which begins entity references,- the string of characters,
]]>
, which ends a CDATA section.
Escaping:
- Escape
<
as<
in character data. - Escape
&
as&
in character data. ]]>
cannot appear in character data; there is no escaped form.
See also:
- Minus in w3c specification grammar
来源:https://stackoverflow.com/questions/64813063/understanding-xml-chardata-ebnf