/
542.txt
351 lines (258 loc) · 17.7 KB
/
542.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
[2] [[XML]] の仕様書で定義されている属性
[DFN[[CODE(XMLa)[[[xml]]:space]]]] は、
[[内容]]中の[[空白]]の扱いを指定します。
[27] この属性は XML [[処理器]]ではなく、 XML [[応用]]の処理器が扱います。
[43] この[[属性]]は、実質的に意味のある使い方はされておらず、 [[XML]]
仕様書上の規定は死文化しています。
* 仕様書
[REFS[
- [1] '''[[XML 1.0]] <http://www.w3.org/TR/REC-xml#sec-white-space>'''
- [29] [CITE@en-GB-x-hixie[HTML Standard]] ([TIME[2015-05-06 10:42:35 +09:00]] 版) <https://html.spec.whatwg.org/#global-attributes:attr-xml-space>
]REFS]
* 意味
[37] [CODE(XMLa)@en[[[xml:space]]]] [[属性]]の意味は、 [[XML]]
仕様書の規定するところが歴史的に曖昧だったこともあり、混乱が見られました。
[38] [[HTML]] では[[空白]]は正規化して[[レンダリング]]されるのが基本です
([CODE(CSS)@en[[[white-space: normal]]]])。 [[IE4 DOM]] のように、
[[DOM]] 上で[[空白]]を省いた実装も存在していました。しかし
[CODE(HTMLe)@en[[[pre]]]] [[要素]]のように、[[空白]]を保持するべき文脈も混在しています。
これを一般化し共通の[[属性]]で記述できるようにするのが本来の
[CODE(XMLa)@en[[[xml:space]]]] [[属性]]の意味だったと推測されます。
[39] 本[[属性]]では[[空白]]を記述されたまま保持するべきか、
[[応用]]依存の「既定の方法」で処理するべきかを指定することができます。
[[XML]] の仕様書では既定の方法がどのような処理であるかを決めていません。
これは[[空白]]を処理するべきだとしても、具体的にどうするべきかは[[応用]]ごとに異なること、
[[XML]] の仕様書は [[XML文書]]の記述方法と適合性を規定するに留まり、
[[データモデル]]の生成も含めてどのような処理を行うかは一切を[[応用]]に委ねていることによると思われます。
いずれにせよ、「何かするべきかもしれないが何かはわからない」との指定がすべての
[[XML]] の[[要素]]で可能とされたことが、混乱の一因となってしまいました。
[40] [[XHTML1]] は [CODE(HTMLe)@en[[[pre]]]] [[要素]]や
[CODE(HTMLe)@en[[[script]]]] [[要素]]など一部の[[要素]]のみで、
[[DTD]] の[[既定値]]によって [CODE(XMLa)@en[[[xml:space]]=[[preserve]]]]
を指定していました。
また [CODE(XML)@en[[[default]]]] の意味も明確にはしていませんでした。
既定のレンダリングのみで [[CSS]] も [[DOM]] も使わないなら、これでも大きな問題はありません。
しかし [[CSS]] で [CODE(CSS)@en[[[white-space]]]] [[特性]]を変更した場合や [[DOM]]
で他の[[要素]]にアクセスした場合に[[空白]]がどうなるのか、
[CODE(HTMLe)@en[[[pre]]]] [[要素]]に [CODE(XMLa)@en[[[xml:space]]]]
[[属性]]を指定した場合にどう表示されるのか、といった疑問が生じます。
[41] [[XHTML2]] はすべての[[要素]]を [CODE(XML)@en[[[xml:space]]=[[preserve]]]]
とする (>>10) という半ば強引な解決策をとりました。 [[CSS]] や [[DOM]]
の問題は起きなくなりますが、 [CODE(XMLa)@en[[[xml:space]]=[[default]]]]
が指定されたらどう処理されるべきなのかは、なお明らかではありませんでした。
当時の [[HTML WG]] の見解 (>>10) には [CODE(XML)@en[[[default]]]] なら[[空白]]が
[[DOM]] には現れなくなるような記述があります。これが [[XML構文解析器]]で[[空白]]が削除されるべきとの理解なのか、
[[XML]] から [[DOM]] ないし [[XML]] から [[XHTML2]] [[DOM]] への変換の過程で[[空白]]が削除されることにしたかったのかはわかりません。
[42] いずれにしても [CODE(XMLa)@en[[[xml:space]]]] [[属性]]の意味は、かなり早い時期に事実上消失していました。
* 属性名
[9] この属性は、 [[XML名前空間]]的には特別な名前空間
[CODE(XML)[[[xml]]]] に属します。 [CODE(XML)[xml:]]
という[[名前空間接頭辞]]は特別なので、
[CODE(XMLa)[xml:space]] 属性は常に [CODE(XMLa)[xml:space]]
という[[修飾名]]です。
なお、この属性は XML 名前空間を使わない XML 文書でも使えます。
[[#comment]]
** 属性値
[4] 属性値:
:[CODE(XML)[[[default]]]]:
空白の取扱いは既定のものとします。
(「既定」の取扱いは応用により決定されます。)
:[CODE(XML)[[[preserve]]]]:
空白を保持します。
(詳細は応用により決定されます。)
この2つ以外の値は取れません。他の値が指定された時は、
XML 処理器はその[[属性指定]]を無視しても'''構いません'''し、
[[誤り]]としても'''構いません'''し、
不正な値をそのまま応用に報告しても'''構いません'''。
応用は不正な値を無視しても拒絶しても'''構いません'''。
[5]
[[DTD]] では [SAMP(XML)[xml:space (default|preserve) #IMPLIED]]
のように定義します ([[列挙型]]で'''なければなりません''')。
(他の属性と同じく、
[[妥当]]であるためには[[属性定義]]が必須です。)
また、必要に応じて
[SAMP(XML)[xml:space (preserve) #FIXED "preserve"]]
のような形で定義することもできます。
[6] 指定が無い場合には、[[直近先祖要素]]への指定が継承されます。
[[根要素]]に指定がない場合の値は応用によります。
[7] >>5 列挙型として宣言されなければならないという規定、
XML 仕様書にはきちんと[Q[宣言される場合]]と限定されているので矛盾はないのですが、
一般に宣言されていない属性の型は [CODE(XML)[[[CDATA]]]]
として扱われてしまいます。その辺が余り美しくないと思います。
([SAMP(XML)[<foo xml:space=" preserve "/>]]
は宣言があれば適当、なければ不適当になってしまいます。)
[8] ''Exclusive XML Canonicalization Version 1.0'' <http://www.w3.org/TR/2002/REC-xml-exc-c14n-20020718/#sec-Enveloping>
では、怪しげな [SAMP(XML)[xml:space="retain"]]
とかいう属性指定が使用例に含まれています。
訂正票 ''Errata of the Exclusive Canonicalization Version 1.0 Specification'' <http://www.w3.org/2002/07/xml-exc-c14n-errata#E01>
で修正されてはおりますが、
''Exclusive XML Canonicalization Version 1.0'' <http://www.w3.org/TR/2001/WD-xml-exc-c14n-20011120>
から1年間誰も気づかなかったというのが素敵です。
* 文脈
[35] [[XML]] 仕様書は、 [CODE(XMLa)@en[[[xml:space]]]] [[属性]]の利用できる文脈について、
[[DTD]] を用いる場合は通常の[[属性]]同様に[[属性定義並び宣言]]で規定できるとしています。
[[XML]] 仕様書は[[整形式]]と[[妥当]]の他の適合性を規定していませんから、
[CODE(XMLa)@en[[[xml:space]]]] [[属性]]が一般にいつ利用できるかは明らかではありません。
一般的には [[XML文書]]中の任意の[[要素]]で (当該[[要素]]の規定で禁止されない限り)
利用できるものと解されています。
[30] [[HTML Standard]] は、[[XML文書]]の任意の[[要素]]で
[CODE(XMLa)@en[[[xml:space]]]] [[属性]]の利用が [[XML]] 仕様書により認められているとし
[SRC[>>29]]、 [[HTML要素]]での利用も禁止していません。しかし、意味はありません (>>31)。
[32] [CODE(MIME)@en[[[text/html]]]] の [[HTML要素]]で [CODE(XMLa)@en[[[xml:space]]]]
[[属性]]を[[直列化]]する方法はありません [SRC[>>29]]。 [[HTML文書]]に
[CODE(XMLa)@en[xml:space]] と書いても、 [[null名前空間]]の [CODE(XMLa)@en[[[xml:space]]]]
[[属性]]となり、 [[[CODE(XML)@en[xml]]名前空間]]の [CODE(XMLa)@en[[[space]]]]
[[属性]]とは解釈されません。
;; [33] [[HTML文書]]たる [[DOM HTML]] の [[HTML要素]]が [CODE(XMLa)@en[[[xml:space]]]]
[[属性]]を持っても[[適合]]するかどうかは、明記されていませんが、 [[XML]]
の場合だけで [[HTML]] の場合には言及されていないのですから、認められていない =
不適合と解釈するべきものです。 ([[直列化]]はできませんが、[[スクリプト]]で追加することは可能です。)
[34] [[HTML文書]] / [CODE(MIME)@en[[[text/html]]]] であっても、 [[SVG要素]]や
[[MathML要素]]なら [CODE(XMLa)@en[[[xml:space]]]] [[属性]]は[[直列化]]できます。
指定された場合、 [[SVG]] や [[MathML]] の仕様に従い解釈されます。
* 処理
[31] [[HTML要素]]では、 [CODE(XMLa)@en[[[xml:space]]]] [[属性]]は効果を持ちません。
[[HTML]] での既定の動作は、空白を保持します。 [SRC[>>29]]
* 歴史
** XML 1.1
[28] [[XML 1.1]] でもまったく同内容の規定がありました。
[REFS[
- [3] [[XML 1.1]] <http://www.w3.org/TR/xml11#sec-white-space>
]REFS]
* 例
[13] [CITE[フィードを表示しています]] ([TIME[2008-12-02 19:14:12 +09:00]] 版) <http://groups.google.com/group/japan.test/feed/atom_v1_0_msgs.xml>
([[Atom]] [[フィード]])
[PRE(XML example code)[
<summary type="html" xml:space="preserve">
test
</summary>
]PRE]
* メモ
[10]
[CITE[XHTML Frequently Answered Questions]] (2004年7月付け)
<http://www.w3.org/MarkUp/2004/xhtml-faq#xmlspace>
> '''Why is [CODE(XMLa)@en[[[xml]]:[[space]]]] set to '[CODE(XML)@en[[[preserve]]]]' on all elements of XHTML? I don't want to see extra space in my output.'''
> The attribute [CODE(XMLa)@en[[[xml]]:[[space]]]] is about ''input'': that is to say, it controls if the spaces will be present in the DOM (i.e. in the internal version of the document inside the browser); it says nothing about what will appear on your screen. Output whitespace is controlled by the CSS property '[CODE(CSS)@en[[[whitespace]]]]'. Set it to '[CODE(CSS)@en[[[pre]]]]' and the spaces in the DOM will be preserved on output; set it to '[CODE(CSS)@en[[[normal]]]]' and the whitespace will be collapsed (CSS3 will have more properties to enable greater control).
> This is the reason that all elements are set to [CODE(XML)@en[[CODE(XMLa)@en[[[xml]]:[[space]]]]="[[preserve]]"]] in XHTML2, otherwise the CSS '[CODE(CSS)@en[[[whitespace]]]]' property would have no effect, and you would have no control over visible whitespace. The default stylesheet will set '[CODE(CSS)@en[[[whitespace]]]]' to '[CODE(CSS)@en[[[normal]]]]' for all elements except [CODE(HTML)@en[<[CODE(HTMLe)@en[[[pre]]]]>]], but you will be free to change them.
[11]
[CITE[XHTML Modularization 1.1 - Conformance Definition]] <http://www.w3.org/TR/2006/WD-xhtml-modularization-20060705/conformance.html#s_conform_user_agent>
;; <IW:XHTML1m12n:"conformance.html#s_conform_user_agent">
[12]
[CITE[Re: xml:space]] ([[Ian Hickson <ian@...>]] 著, [TIME[2008-04-28 01:28:31 +09:00]] 版) <http://permalink.gmane.org/gmane.org.w3c.whatwg.discuss/13893>
[14] [CITE[SMIL 3.0 smilText]] ([TIME[2008-12-02 00:45:09 +09:00]] 版) <http://www.w3.org/TR/2008/REC-SMIL3-20081201/smil-text.html#adef-textSpace>
[15] [CITE[Document Structure – SVG Tiny 1.2]] ([TIME[2008-12-20 02:31:29 +09:00]] 版) <http://www.w3.org/TR/2008/REC-SVGTiny12-20081222/struct.html#XMLSpaceAttribute>
[16] [CITE[Text – SVG Tiny 1.2]] ([TIME[2008-12-20 02:31:29 +09:00]] 版) <http://www.w3.org/TR/2008/REC-SVGTiny12-20081222/text.html#WhiteSpace>
[17] [[ECMA-376]] Part 1 Second Edition 17.3.3.7
>xml:space (Content
Contains Significant
Whitespace)
>Namespace:
http://www.w3.org/XML/1998/namespace
>Specifies how white space should be handled for the contents of this element using the
W3C space preservation rules.
>[Example: Consider the following run contained within a WordprocessingML document:
[PRE(XML example code)[
<w:r>
<w:t> significant whitespace </w:t>
</w:r>
]PRE]
Although there are three spaces on each side of the text content in the run, that
whitespace has not been specifically marked as significant, therefore it is subject to the
space preservation rules currently specified in that run's scope. end example]
>The possible values for this attribute are defined by §2.10 of the XML 1.0 specification.
[18] >>17 はこれだけしか説明がないのですが・・・。文脈から察するに、
[CODE(XML)@en[[[default]]]] だと [[OOXML]] の既定の処理にしたがって[[空白]]は除去されることがあり、
[CODE(XML)@en[[[preserve]]]] だと [[XML]] で定義されているようにそのまま保持されるみたいです。
[19] [CITE@en[Web Applications 1.0 r5527 Mention xml:space since people seem unable to read the XML spec.Fixing http://www.w3.org/Bugs/Public/show_bug.cgi?id=10197]]
( ([TIME[2010-09-29 02:44:00 +09:00]] 版))
<http://html5.org/tools/web-apps-tracker?from=5526&to=5527>
[20] [CITE@en[XSLT 2.0 and XQuery 1.0 Serialization (Second Edition)]]
( ([TIME[2010-12-17 00:08:20 +09:00]] 版))
<http://www.w3.org/TR/2010/REC-xslt-xquery-serialization-20101214/#xml-indent>
[21] [CITE[Document Structure – SVG 1.1 (Second Edition)]]
( ([TIME[2011-08-10 12:35:27 +09:00]] 版))
<http://www.w3.org/TR/2011/REC-SVG11-20110816/struct.html#LangSpaceAttrs>
[22] [CITE@en[Scalable Vector Graphics (SVG) Tiny 1.2 Specification]]
( ([TIME[2008-12-22 23:20:34 +09:00]] 版))
<http://www.w3.org/TR/SVGTiny12/single-page.html#text-WhiteSpace>
[23] [CODE(XMLa)@en[[[xml:space]]]] [[属性]]を[[HTML文書]]中の[[HTML要素]]で使用することは禁じられていません。
([CODE(MIME)@en[[[text/html]]]] ではそれを直接記述できませが。)
;; [CODE(XMLa)@en[[[xml:lang]]]] では禁止されていませんが。 [CODE(XMLa)@en[[[xml:space]]]]
は実用性皆無で誰も使っていないので禁止してもしなくても無害だからでしょうか。
[24] [[Node.text]] は [CODE(XMLa)@en[[[xml:space]]]] によって挙動が変わるそうです。
[25] [CITE@en-US[Internationalization Tag Set (ITS) Version 2.0]]
( ([TIME[2013-10-27 19:39:43 +09:00]] 版))
<http://www.w3.org/TR/its20/#preservespace>
[26] [CITE@en[Proposals/dropxmlattributes - SVG]]
([TIME[2015-01-30 22:52:07 +09:00]] 版)
<https://www.w3.org/Graphics/SVG/WG/wiki/Proposals/dropxmlattributes>
[FIG(quote)[
[FIGCAPTION[
[36] [CITE@ja[XAML における xml:space の処理]]
([TIME[2015-06-25 21:31:20 +09:00]] 版)
<https://msdn.microsoft.com/ja-jp/library/ms788720(v=vs.110).aspx>
]FIGCAPTION]
> xml:space 属性の既定値は、リテラル値の "default" です。 値が "default" の場合、または xml:space がまったく示されていない場合、重要な空白の解析は、トピック「XAML での空白の処理」で定義されているように、既定の動作で処理されます。
> オブジェクト要素のコンテンツ内で空白を保持するには、そのオブジェクト要素で xml:space="preserve" を指定します。
> ほとんどの解釈では、xml:space 属性の効果と属性の値は、子要素に反映されます。
]FIG]
[44] [CITE@en[Use text-space-collapse property for xml:space="preserve" handling in… · w3c/svgwg@72e4df7]]
([TIME[2016-01-15 19:02:35 +09:00]] 版)
<https://github.com/w3c/svgwg/commit/72e4df79e0805e700b7be4532fbae700b04ca506>
[FIG(quote)[
[FIGCAPTION[
[45] [CITE@en[RFC 7749 - The "xml2rfc" Version 2 Vocabulary]]
([TIME[2016-02-04 22:54:51 +09:00]] 版)
<https://tools.ietf.org/html/rfc7749#section-2.5.8>
]FIGCAPTION]
> "preserve" is both the default value and the only meaningful setting
> (because that's what the <artwork> element is for).
]FIG]
[FIG(quote)[
[FIGCAPTION[
[46] [CITE@en[RFC 7749 - The "xml2rfc" Version 2 Vocabulary]]
([TIME[2016-02-04 22:54:51 +09:00]] 版)
<https://tools.ietf.org/html/rfc7749#section-2.36.2>
]FIGCAPTION]
> According to the DTD, the default value is "preserve". However,
> tests show that it doesn't have any effect on processing; thus, this
> attribute will be removed in future versions of the vocabulary.
]FIG]
[FIG(quote)[
[FIGCAPTION[
[47] ([TIME[2016-03-18 02:10:13 +09:00]] 版)
<https://lists.w3.org/Archives/Public/www-archive/feed.rss>
]FIGCAPTION]
>
> <content type="xhtml">
> <div xmlns="http://www.w3.org/1999/xhtml">
> <pre id="body" xml:space="preserve">
]FIG]
[FIG(quote)[
[FIGCAPTION[
[48] [CITE[Text – SVG 1.1 (Second Edition)]]
( ([TIME[2011-08-10 12:35:27 +09:00]]))
<https://www.w3.org/TR/SVG11/text.html#WhiteSpace>
]FIGCAPTION]
> SVG supports the standard XML attribute ‘xml:space’ to specify the handling of white space characters within a given ‘text’ element's character data. Note that any child element of a ‘text’ element may also have an ‘xml:space’ attribute which will apply to that child element's text content.
]FIG]
[FIG(quote)[
[FIGCAPTION[
[49] [CITE[Scalable Vector Graphics (SVG) 2]]
( ([TIME[2016-05-25 12:15:53 +09:00]]))
<https://svgwg.org/svg2-draft/single-page.html#struct-WhitespaceProcessingXMLSpaceAttribute>
]FIGCAPTION]
> Deprecated XML attribute to specify whether white space is preserved in character data. The only possible values are the strings 'default' and 'preserve', without white space.
]FIG]
[50] [CITE@en[SVG Working Group Teleconference -- 03 Mar 2011]]
( ([TIME[2011-03-04 13:18:16 +09:00]]))
<https://www.w3.org/2011/03/03-svg-minutes.html#item04>
[FIG(quote)[
[FIGCAPTION[
[51] ([TIME[2016-10-21 13:08:17 +09:00]])
<http://www.niso.org/apps/group_public/download.php/15933/z39_96-2015.pdf>
]FIGCAPTION]
> @xml:space Space
> When printing or displaying the associated element, all white space (such as tabs, ordinary spaces,
> and line breaks) should be preserved.
]FIG]