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

前端 未结 7 1287
攒了一身酷
攒了一身酷 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 01:43

    Double quotes in text nodes can be represented either as the double-quote character or as the " entity. Double quotes in attribute values can be represented as the double-quote character if the value is delimited by single quotes, and vice versa; otherwise, escape them as "

    This is only relevant if you're a) editing XML in a non-XML-aware text editor or b) creating XML programmatically through string manipulation. Generally speaking, you should avoid (a) unless you really know what you're doing, or at least have a way of checking the well-formedness of your XML after editing is complete.

    And you should avoid (b) under all circumstances. Never create XML through string manipulation; always use a DOM or some other tool.

提交回复
热议问题