XML 不间断空格 [英] XML non breaking space

查看:43
本文介绍了XML 不间断空格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 XLST 文件将 XML 转换为 XML.

I am using XLST files to transform XML to XML.

什么是空间的有效表示?

What are valid representation of space?

<xsl:text> </xsl:text>
<xsl:text>&nbsp;</xsl:text>
<xsl:text>&#160;</xsl:text>

推荐答案

XML 除了 &lt;&gt;&amp;&quot;&apos;.

XML does not have any named entities besides &lt;, &gt;, &amp;, &quot;, and &apos;.

所有其他字符都可以逐字表示,前提是您在 XML 声明中声明了正确的编码(例如 ),并以该编码实际保存 XML 文件.声明 UTF-8 是可选的,因为这是 XML 的默认设置.

All other characters can be represented verbatim, given that you declared the right encoding in the XML declaration (e.g. <?xml version="1.0" encoding="..." ?>), and actually saved the XML file in that encoding. Declaring UTF-8 is optional, as this is the default for XML.

权利"编码是包含您要使用的所有字符的任何编码.选择 Unicode 既流行又实用,但 XML 不在乎,只要您声明正确即可.

The "right" encoding is any encoding that contains all the characters you want to use. Choosing Unicode is both popular and practical, but XML does not care as long as you've declared it properly.

所选字符集支持的任何字符都可以按原样使用,但在 XML 中具有特殊含义的字符除外(<>&必须总是被转义,而',或",只有必须被转义在某些情况下).所有其他字符都可以转义,但您不需要.

Any character the chosen character set supports you can use as-is, with the exception of those that have special meaning in XML (<, >, or &, which must always be escaped, and ', or ", which only must be be escaped in certain situations). All other characters can be escaped, but you don't need to.

为了说明这一点,就结果文档(即 XML 解析器读取文件后获得的对象)而言,这些表示是 100% 等效的:

To make a point, these representations are 100% equivalent in terms of the resulting document (i.e. the object you get after an XML parser has read the file):

<foo>Test Test</foo>          <!-- unescaped - given that the " " really is char code 160 -->

<foo>Test&#160;Test</foo>     <!-- partially escaped -->

<foo>&#84;&#101;&#115;&#116;&#160;&#84;&#101;&#115;&#116;</foo>   <!-- decimal escaped -->

<foo>&#x54;&#x65;&#x73;&#x74;&#xa0;&#x54;&#x65;&#x73;&#x74;</foo> <!-- hex escaped -->

不间断空格与字母T"没有任何特殊或不同.为方便使用文本编辑器编辑 XML 文件时,您可能希望选择转义形式,但没有技术要求可以这样做.

The non-breaking space is in no way special or different from, say, the letter "T". For convenience when editing the XML file with a text editor, you might want to choose the escaped form, but there is no technical requirement to do that.

请注意,您可以使用 DOCTYPE 声明自定义命名实体(如 &nbsp;).

Note that you can declare custom named entities (like &nbsp;) using a DOCTYPE.

<!DOCTYPE xsl:stylesheet [
   <!ENTITY nbsp "&#160;">
]>

但鉴于 XML 接受几乎不需要的任何字符这一事实.尤其是当您使用适当的工具(如 DOM API)创建文档时.

But given the fact that XML accepts any character that's hardly ever necessary. Especially not when you create the document using a proper tool, like a DOM API.

这篇关于XML 不间断空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆