XML 回车编码
我希望在 xml 节点中表示回车符。
我尝试过保留空白、十六进制实体,但没有成功 - 和 \n。通过浏览器查看。
示例
<Quote>
Alas, poor Yorick!
I knew him
</Quote>
谢谢。
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.
Example
<Quote>
Alas, poor Yorick!
I knew him
</Quote>
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
要将 CR 插入 XML,您需要使用其字符实体
。
这是因为兼容的 XML 解析器必须在解析之前将 CRLF 和任何不跟有 LF 的 CR 转换为单个 LF。此行为在行尾处理中定义XML 1.0 规范的部分。
To insert a CR into XML, you need to use its character entity
.
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 handling section of the XML 1.0 specification.
xml:space="preserve"
必须适用于所有兼容的 XML 解析器。但是,请注意,在 HTML 中,换行符只是空格而不是换行符(这是用
(X)HTML 标记表示的,也许这就是您遇到的问题 。gt;
您还可以添加
和/或
来插入 CR/LF 字符
xml:space="preserve"
has to work for all compliant XML parsers.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.You can also add
and/or
to insert CR/LF characters.
浏览器不会可靠地向您显示空白区域。我推荐使用 Linux 'od' 命令来查看里面到底有什么。兼容的 XML 解析器将尊重您列出的所有方法。
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.