What's the accepted way of storing quoted data in XML?

前端 未结 7 1219
攒了一身酷
攒了一身酷 2021-01-04 01:01

What\'s the accepted way of storing quoted data in XML?

For example, for a node, which is correct?

  • (a) Jesse \"The Body\" Ventura
相关标签:
7条回答
  • 2021-01-04 02:01

    Character data inside XML elements can contain quote characters without escaping them. The only characters that are not permitted inside an XML element are '<', '&' and '>' (and the '>' character is only disallowed if it's part of a "]]>" sequence of characters.

    That's not to say that escaping the quotes is not a good idea - I'm just saying that not escaping the quotes is perfectly valid XML. See section 2.4 - "Character Data and Markup" in the XML spec.

    So both (a) and (c) are OK.

    As far as attributes are concerned, attribute values can be enclosed in either single or double quotes, so if it contains one or the other you can use the opposite one to enclose the value. If it'll contain both, then you'll have to use a character entity for one or both.

    As far as 'curly-quotes' are concerned, if you're talking about the special, non-ASCII quotes that Word sometimes converts quotes to - they have no special meaning in XML, so you can do whichever (but they can't be used to enclose attribute values". You'll also need to make sure the character encoding for the document is correct, so they are interpreted correctly.

    0 讨论(0)
提交回复
热议问题