XML 回车编码
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2265966/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
XML Carriage return encoding
提问by user273502
I was looking to represent a carriage return within an xml node.
I have tried a whitespace preserve, hex entity with no luck-
and a \n. viewing via a browser.
我希望在 xml 节点中表示回车。
我尝试了一个空白保留,没有运气的十六进制实体和一个 \n。通过浏览器查看。
Example
例子
<Quote>
Alas, poor Yorick!
I knew him
</Quote>
Thanks.
谢谢。
回答by Lachlan Roche
To insert a CR into XML, you need to use its character entity .
要将 CR 插入 XML,您需要使用其字符实体 。
This is because compliant XML parsers must, before parsing, translate CRLF and any CR not followed by a LF to a single LF. This behavior is defined in the End-of-Line handlingsection of the XML 1.0 specification.
这是因为兼容的 XML 解析器必须在解析之前将 CRLF 和任何没有跟在 LF 后面的 CR 转换为单个 LF。此行为在 XML 1.0 规范的行尾处理部分中定义。
回答by Lucero
xml:space="preserve"has to work for all compliant XML parsers.
xml:space="preserve"必须适用于所有兼容的 XML 解析器。
However, note that in HTML the line break is just whitespace and NOT a line break (this is represented with the <br />(X)HTML tag, maybe this is the problem which you are facing.
但是,请注意,在 HTML 中,换行符只是空格而不是换行符(这用<br />(X)HTML 标记表示,也许这就是您面临的问题。
You can also add and/or to insert CR/LF characters.
您还可以添加 和/或 插入 CR/LF 字符。
回答by bmargulies
A browser isn't going to show you white space reliably. I recommend the Linux 'od' command to see what's really in there. Comforming XML parsers will respect all of the methods you listed.
浏览器不会可靠地向您显示空白区域。我建议使用 Linux 'od' 命令来查看里面到底有什么。符合标准的 XML 解析器将尊重您列出的所有方法。

