[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]] 版) [14] [CITE[SMIL 3.0 smilText]] ([TIME[2008-12-02 00:45:09 +09:00]] 版) [15] [CITE[Document Structure – SVG Tiny 1.2]] ([TIME[2008-12-20 02:31:29 +09:00]] 版) [16] [CITE[Text – SVG Tiny 1.2]] ([TIME[2008-12-20 02:31:29 +09:00]] 版) [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)[ significant whitespace ]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]] 版)) [20] [CITE@en[XSLT 2.0 and XQuery 1.0 Serialization (Second Edition)]] ( ([TIME[2010-12-17 00:08:20 +09:00]] 版)) [21] [CITE[Document Structure – SVG 1.1 (Second Edition)]] ( ([TIME[2011-08-10 12:35:27 +09:00]] 版)) [22] [CITE@en[Scalable Vector Graphics (SVG) Tiny 1.2 Specification]] ( ([TIME[2008-12-22 23:20:34 +09:00]] 版))