Understanding XML CharData EBNF

你说的曾经没有我的故事 提交于 2021-01-05 06:41:30

问题


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 &lt; in character data.
  • Escape & as &amp; 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!