[2] [[XML]] の仕様書で定義されている属性 [DFN[[CODE(XMLa)[[[xml]]:space]]]] は、 [[内容]]中の[[空白]]の扱いを指定します。 この属性は XML [[処理器]]ではなく、 XML [[応用]]の処理器が扱います。 XML や [[SGML]] 的には一般の属性とほとんど変わりありません。 仕様書: - [1] [[XML 1.0]] - [3] [[XML 1.1]] [[#comment]] ** 属性名 [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)[]] は宣言があれば適当、なければ不適当になってしまいます。) [8] ''Exclusive XML Canonicalization Version 1.0'' では、怪しげな [SAMP(XML)[xml:space="retain"]] とかいう属性指定が使用例に含まれています。 訂正票 ''Errata of the Exclusive Canonicalization Version 1.0 Specification'' で修正されてはおりますが、 ''Exclusive XML Canonicalization Version 1.0'' から1年間誰も気づかなかったというのが素敵です。 * 例 [13] [CITE[フィードを表示しています]] ([TIME[2008-12-02 19:14:12 +09:00]] 版) ([[Atom]] [[フィード]]) [PRE(XML example code)[ test ]PRE] * メモ [10] [CITE[XHTML Frequently Answered Questions]] (2004年7月付け) > '''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]] ;; [12] [CITE[Re: xml:space]] ([[Ian Hickson ]] 著, [TIME[2008-04-28 01:28:31 +09:00]] 版)