HTML — XML 構文

14. ~XML構文

注記: この節は、 ~XML資源~用の規則のみを述べる。 `text/html$mt 資源~用の規則は、 `§ ~HTML構文@~HTMLwriting#syntax$ にて論じられる。 ◎ This section only describes the rules for XML resources. Rules for text/html resources are discussed in the section above entitled "The HTML syntax".

  • ~XML構文解析器が[ ~byte/文字 ]たちが成す並びを`文書$の中へ対応付けるための規則を規範的に定義する仕様は無い。 ◎ the fact that there is no specification which defines the rules for how an XML parser must map a string of bytes or characters into a Document object,\
  • ~XML構文は,本質的に保守されておらず、 さらなる特能が~XML構文に追加されることは,期待されていない (そのような特能が`~HTML構文@~HTMLwriting#syntax$に追加されたとしても)。 ◎ as well as the fact that the XML syntax is essentially unmaintained — in that, it’s not expected that any further features will ever be added to the XML syntax (even when such features have been added to the HTML syntax).

【 参考: ~HTML構文との相違点は、 `HTML vs. XHTML@https://wiki.whatwg.org/wiki/HTML_vs._XHTML$cite にてまとめられている (更新~日が 10 年以上前だが)。 】

14.1. ~XML構文で文書を書くとき

注記: ~HTML用の~XML構文は、 以前は “XHTML” と称されていたが, この仕様はその用語を利用しない (他にも理由はあるが、 ~MathMLや~SVGの~HTML構文には,そのような用語は利用されていないので)。 ◎ The XML syntax for HTML was formerly referred to as "XHTML", but this specification does not use that term (among other reasons, because no such term is used for the HTML syntaxes of MathML and SVG).

~XML用の構文は、 `XML$r, `XMLNS$r にて定義される。 ◎ The syntax for XML is defined in XML and Namespaces in XML. [XML] [XMLNS]

この仕様は、 構文~levelの要件として,[ ~XMLにて本式に定義されるものを超えるもの ]は何も定義しない。 ◎ This specification does not define any syntax-level requirements beyond those defined for XML proper.

~XML文書は、 欲されるなら `DOCTYPE^c を包含してもヨイが, この仕様に適合するためには要求されない。 この仕様は、 ~publicIDも~systemIDも定義しないし, 正式な~DTDも供さない。 ◎ XML documents may contain a DOCTYPE if desired, but this is not required to conform to this specification. This specification does not define a public or system identifier, nor provide a formal DTD.

注記: `XML^cite によれば、 ~XML処理器が[ ~DOCTYPE内から参照されている外部~DTD~subset ]を処理することは,保証されない。 このことは、 例えば,[ ~XML文書~内の文字に,外部~file内に定義される`実体~参照$を利用する ]ことは安全でないことを意味する ( `<^c, `>^c, `&^c, `"^c, `'^c は除いて)。 ◎ According to XML, XML processors are not guaranteed to process the external DTD subset referenced in the DOCTYPE. This means, for example, that using entity references for characters in XML documents is unsafe if they are defined in an external file (except for <, >, &, ", and ').

14.2. ~XML文書の構文解析-法

この節では、 ~XMLと~DOMとの間の関係性 — とりわけ、 それが~HTMLとどう相互作用するかについて — を述べる。 ◎ This section describes the relationship between XML and the DOM, with a particular emphasis on how this interacts with HTML.

この仕様の目的における `~XML構文解析器@ は、[ `XML^cite にて与えられる,[ ~byte/文字 ]たちが成す連なりを`文書$の中へ対応付ける規則 ]に従う構成子である。 ◎ An XML parser, for the purposes of this specification, is a construct that follows the rules given in XML to map a string of bytes or characters into a Document object.

注記: これを書いた時点では、 そのような規則は実際には存在しない。 ◎ At the time of writing, no such rules actually exist.

各`~XML構文解析器$ %構文解析器 には、 ある`文書$ — 以下 %文書 — が結付けられる。 %文書 は、 その作成-時に ある`~XML構文解析器$に結付けられるか, %構文解析器 により暗黙的に作成される。 ◎ An XML parser is either associated with a Document object when it is created, or creates one implicitly.

~UAは、 `XML$r, `XMLNS$r, `DOM$r による定義に従って, %文書 を[ 構文解析器に渡された入力が成す~tree構造を表現する~DOM~nodeたち ]で拡充するモノトスル — その際に要素 %要素 を表現する~DOM~nodeを作成するときは、 次に従うモノトスル。 ◎ This Document must then be populated with DOM nodes that represent the tree structure of the input passed to the parser, as defined by XML, Namespaces in XML, and DOM. When creating DOM nodes representing elements,\

  • [ `~tokenから要素を作成する$ ~algo ]または[ 適切な,~XML~data構造に対し演算する等価な何か ]を利用して,次を確保する ⇒# %要素 用に適正な`要素~interface$が作成される/ %要素 が`~custom要素$である場合,それが正しく設定しておかれる ◎ the create an element for a token algorithm or some equivalent that operates on appropriate XML data structures must be used, to ensure the proper element interfaces are created and that custom elements are set up correctly.
  • ~DOM変異~event【 `MutationEvent$I 】は、[ `~XML構文解析器$が %文書 ~treeに対し遂行する演算 ]用には発火しない。 ◎ DOM mutation events must not fire for the operations that the XML parser performs on the Document's tree,\
  • [ %要素 が個別に付加された/ %要素 の各~属性が個別に設定された ]かのように動作して,[ %要素 が %文書 の中へ挿入されたとき/ %要素 の属性が設定されたとき ]に何が起こるかに関する[ この仕様~内の各種~規則 ]を誘発する。 その際には、 `変異~observer$に関する `DOM^cite の要件により, 変異~observerを`発火する^em 【`参照@~DOM4#queueing-a-mutation-record$】 ことになる (変異~eventとは違って)。 `XML$r `XMLNS$r `DOM$r `UIEVENTS$r ◎ but the user agent must act as if elements and attributes were individually appended and set respectively so as to trigger rules in this specification regarding what happens when an element is inserted into a document or has its attributes set, and DOM's requirements regarding mutation observers mean that mutation observers are fired (unlike mutation events). [XML] [XMLNS] [DOM] [UIEVENTS]
  • %要素 の開始~tagが構文解析されてから[ %要素 の終了~tagが構文解析されるか, 構文解析器が整形式性~errorを検出する ]までの間は、 %要素 は`~open要素~stack$内にあるかのように動作する。 ◎ Between the time an element's start tag is parsed and the time either the element's end tag is parsed or the parser detects a well-formedness error, the user agent must act as if the element was in a stack of open elements.

    注記: これは、 種々の要素により[ `~open要素~stack$から~popされた後に,ある種の処理nを開始する ]ために限り,利用される。 ◎ This is used by various elements to only start certain processes once they are popped off of the stack of open elements.

この仕様は、[ ~UAが外部~実体を検索取得するときに利用するべきである,追加的な情報 ]を以下に供する。 次に挙げる~publicIDは、 すべて, `この~link先にある~data@HTML-resources/external-entity.txt$†に対応する (その内容は、 `§ 有名~文字~参照@~HTMLcharrefs$ に挙げる一連の名前~用に`実体~宣言$を包含している~DTDである `XML$r ): ◎ This specification provides the following additional information that user agents should use when retrieving an external entity: the public identifiers given in the following list all correspond to the URL given by this link. (This URL is a DTD containing the entity declarations for the names listed in the named character references section.) [XML]

【† 原文では,~source内に~linkとして — `a^e 要素の `href^a 属性~内に `data:^c ~URLとして base64 符号化された形で — 直に~DTDが記されているが、 編集上の都合により,この訳では `その内容^emを外部~資源(~ASCII~text)として与えることにする。 】

  • `-//W3C//DTD XHTML 1.0 Transitional//EN^c
  • `-//W3C//DTD XHTML 1.1//EN^c
  • `-//W3C//DTD XHTML 1.0 Strict//EN^c
  • `-//W3C//DTD XHTML 1.0 Frameset//EN^c
  • `-//W3C//DTD XHTML Basic 1.0//EN^c
  • `-//W3C//DTD XHTML 1.1 plus MathML 2.0//EN^c
  • `-//W3C//DTD XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN^c
  • `-//W3C//DTD MathML 2.0//EN^c
  • `-//WAPFORUM//DTD XHTML Mobile 1.0//EN^c

~UAは、 上に挙げた~publicIDのいずれかが利用されているときは:

  • 上述した外部~実体の内容を検索取得するよう試みるべきである。
  • 他の外部~実体の内容を検索取得するよう試みるべきでない。
◎ Furthermore, user agents should attempt to retrieve the above external entity's content when one of the above public identifiers is used, and should not attempt to retrieve any other external entity's content.

注記: これは厳密には, `XML^cite `XML$r に対する`故意的な違反$ではないが、 ~XML仕様が課す要件の精神には反する。 その動機は、[ 外部~subsetを取扱うための~network~accessを~UAに要求する ]ことなく,[ すべての~UAが,実体を相互運用可能な流儀で取扱う ]ことが欲されていることにある。 ◎ This is not strictly a violation of XML, but it does contradict the spirit of XML's requirements. This is motivated by a desire for user agents to all handle entities in an interoperable fashion without requiring any network access for handling external subsets. [XML]

`~XML構文解析器$は、 `~XML~scriptingの~supportは可能化-@ されるか, `~XML~scriptingの~supportは不能化-@ される下で,呼出される。 他が指定されない限り、 `~XML~scriptingの~supportは可能化-$されて呼出されるとする。 ◎ XML parsers can be invoked with XML scripting support enabled or XML scripting support disabled. Except where otherwise specified, XML parsers are invoked with XML scripting support enabled.

`~XML構文解析器$ %構文解析器 が,`~XML~scriptingの~supportは可能化-$された下で `script$e 要素 %script を作成したときは: ◎ When an XML parser with XML scripting support enabled creates a script element,\

  • %script を次に従って設定しておくモノトスル:

    1. %script の`構文解析器~文書$scE ~SET 【 %構文解析器 に結付けられた`文書$ 】
    2. %script の`非同期cを強制するか$scE ~SET ~F
    3. ~IF[ %構文解析器 は`~XML素片の構文解析~algo$の一部として作成されたものである ] ⇒ %script の`すでに開始したか$scE ~SET ~T
    ◎ it must have its parser document set and its force async set to false. If the parser was created as part of the XML fragment parsing algorithm, then the element's already started must be set to true.\
  • 後続して, %script の終了~tagを構文解析するときは、 次を遂行するモノトスル: ◎ When the element's end tag is subsequently parsed, the user agent must perform\

    1. %文書 ~LET %構文解析器 に結付けられた`文書$ ◎ ↓
    2. `小task~checkpointを遂行する$ ◎ a microtask checkpoint, and then\
    3. `~script要素を準備する$( %script ) ◎ prepare the script element.\
    4. ~IF[ %文書 の`構文解析器を阻んでいる~script$ ~EQ %script ]: ◎ If this causes there to be a pending parsing-blocking script, then the user agent must run the following steps:

      1. この段を終えるまでは、 `~event~loop$が[ %構文解析器 を呼出した`~task$ ]を走らすことはないよう, %構文解析器 を阻む。

        ~AND↓ が満たされるまで`~event~loopを回す$:

        • `~scriptを阻んでいる~stylesheetは在るか?$( %文書 ) ~EQ ~F
        • %script の`構文解析器にて実行されるに準備済みか$scE ~EQ ~T
        ◎ Block this instance of the XML parser, such that the event loop will not run tasks that invoke it. ◎ Spin the event loop until the parser's Document has no style sheet that is blocking scripts and the pending parsing-blocking script's ready to be parser-executed is true. ◎ Unblock this instance of the XML parser, such that tasks that invoke it can again be run.
      2. `~script要素を実行する$( %script ) ◎ Execute the pending parsing-blocking script.
      3. %文書 の`構文解析器を阻んでいる~script$ ~SET ~NULL ◎ Set the pending parsing-blocking script to null.

注記: `~XML文書$用には `document.write()$m ~APIは可用でないので、 `~HTML構文解析器$における複階性を成すかなりの部分は,`~XML構文解析器$においては必要なくなる。 ◎ Since the document.write() API is not available for XML documents, much of the complexity in the HTML parser is not needed in the XML parser.

注記: `~XML~scriptingの~supportは不能化-$された`~XML構文解析器$においては、 これは起こらない。 ◎ When the XML parser has XML scripting support disabled, none of this happens.

`~XML構文解析器$が `template$e 要素に~nodeを付加するときは、 それに代えて, 要素の`~template内容$( `DocumentFragment$I ~node)に~nodeを付加するモノトスル。 ◎ When an XML parser would append a node to a template element, it must instead append it to the template element's template contents (a DocumentFragment node).

注記: これは、 `XML^cite `XML$r に対する`故意的な違反$である — あいにく,~XMLを正式に拡張することは、 `template$e 処理に必要な方式ではできないので。 `XML$r ◎ This is a willful violation of XML; unfortunately, XML is not formally extensible in the manner that is needed for template processing. [XML]

`~XML構文解析器$が作成する `Node$I ~objの`~node文書$は、 その挿入-先の~nodeの`~node文書$に設定するモノトスル。 ◎ When an XML parser creates a Node object, its node document must be set to the node document of the node into which the newly created node is to be inserted.

この仕様における ある種の~algoは、 いっときに何個かの文字を `構文解析器に投入する@ 。 そのような事例では、 `~XML構文解析器$は,[ それらの文字~すべてを連結した 1 個の文字列 ]に面したかのように動作するモノトスル。 ◎ Certain algorithms in this specification spoon-feed the parser characters one string at a time. In such cases, the XML parser must act as it would have if faced with a single string consisting of the concatenation of all those characters.

`~XML構文解析器$は、 入力の終端に達したときは,`~HTML構文解析器$と同じ規則に従って`構文解析を停止する$モノトスル。 `~XML構文解析器$は`中止される@~HTMLparsing#abort-a-parser$こともあるが、 それも,`~HTML構文解析器$に対するときと同じ仕方で行うモノトスル。 ◎ When an XML parser reaches the end of its input, it must stop parsing, following the same rules as the HTML parser. An XML parser can also be aborted, which must again be done in the same way as for an HTML parser.

適合性~検査器の目的においては、 `~XML構文$であるものと決定された資源は,`~XML文書$になる。 ◎ For the purposes of conformance checkers, if a resource is determined to be in the XML syntax, then it is an XML document.

14.3. ~XML素片への直列化-法

`~XML素片に直列化する@ ~algoは、 所与の ([ `Document$I / `Element$I ]~node %~node ) に対し, %~node を表現する~XML素片を返すか, 例外を投出する。 ◎ The XML fragment serialization algorithm for a Document or Element node either returns a fragment of XML that represents that node or throws an exception.

この~algoは、 下に与えるどの~error事例も適用されないならば, ~AND↓ を満たす文字列を返すモノトスル: ◎ ↓

  • %~node に応じて ⇒# `Document$I である場合,`文書~実体$の形を成す/ `Element$I である場合,`内部~一般解析対象~実体$の形を成す ◎ For Documents, the algorithm must return a string in the form of a document entity, if none of the error cases below apply. ◎ For Elements, the algorithm must return a string in the form of an internal general parsed entity, if none of the error cases below apply.
  • ~XML名前空間整形式である ◎ In both cases, the string returned must be XML namespace-well-formed and\
  • 【!`~tree順序$による, %~node に`関連な子~node群$すべて】 %~node に`関連な子~node群$と同型†な直列化である ◎ must be an isomorphic serialization of all of that node's relevant child nodes, in tree order.\

    ~UAは、 直列化における[ 名前空間~接頭辞/名前空間~宣言 ]を調整してもヨイ (また,一部の事例では、 名前空間整形式~XMLを得するために,~~実際にそうするよう強いられることもある)。 ~UAは、 ~DOM内の `Text$I ~nodeを表現するときは,普通の~textに文字~参照を混ぜてもヨイ。 ◎ User agents may adjust prefixes and namespace declarations in the serialization (and indeed might be forced to do so in some cases to obtain namespace-well-formed XML). User agents may use a combination of regular text and character references to represent Text nodes in the DOM.

    【† 同型( `isomorphic^en ) — この語に技術的に特別な定義があるのかは不明だが、 おそらく,直列化した結果を構文解析した結果が元どおりになる ([ 2 つの文字列を構文解析した結果が同じ~DOMを生産するならば、 それらは同型である ]という関係に基づく) ことを意味すると思われる。 】

    ~node %~node に `関連な子~node群@ は、[ %~node は `template$e 要素であるならば %~node の`~template内容$/ ~ELSE_ %~node ]の`子~群$として与えられる。 ◎ A node's relevant child nodes are those that apply given the following rules: • For template elements •• The relevant child nodes are the child nodes of the template element's template contents, if any. • For all other nodes •• The relevant child nodes are the child nodes of node itself, if any.

  • %~node は `Element$I である場合、 次が満たされる ⇒ 前項の直列化を成す ある要素が名前空間を伴わない場合には、 当の要素の視野に入るどこかで, 既定の名前空間が明示的に空~文字列として宣言されている `XML$r `XMLNS$r

    ( %~node が `Document$I である場合、 これは,適用されない。)

    ◎ For Elements, if any of the elements in the serialization are in no namespace, the default namespace in scope for those elements must be explicitly declared as the empty string.\ (This doesn't apply in the Document case.) [XML] [XMLNS]

この節の目的においては、 内部~一般解析対象~実体 %実体 は, 次を満たすならば~XML名前空間整形式であると見なされる ⇒ 次を満たす 1 個の要素からなる文書は、 ~XML名前空間整形式になる ⇒ [ %実体 を内容とする ]~AND[ 名前空間~宣言を伴わない ] ◎ For the purposes of this section, an internal general parsed entity is considered XML namespace-well-formed if a document consisting of an element with no namespace declarations whose contents are the internal general parsed entity would itself be XML namespace-well-formed.

直列化されている~DOM下位tree内に[ 次に挙げるいずれかに該当する~error事例 ]が見出されたときは、 ~algoは,文字列を返さずに `InvalidStateError$E 例外を投出するモノトスル: ◎ If any of the following error cases are found in the DOM subtree being serialized, then the algorithm must throw an "InvalidStateError" DOMException instead of returning a string:

  • `Document$I ~nodeの子に要素~nodeが無い。 ◎ A Document node with no child element nodes.
  • `DocumentType$I ~nodeは外部~subset~publicIDを有していて,それは ~XML `PubidChar^P 生成規則に合致しない文字を包含している。 `XML$r ◎ A DocumentType node that has an external subset public identifier that contains characters that are not matched by the XML PubidChar production. [XML]
  • `DocumentType$I ~nodeは外部~subset~systemIDを有していて,それは次を満たしている ⇒ [ `0022^U `"^smb, `0027^U `'^smb の両者を包含している ]~OR[ ~XML `Char^P 生成規則に合致しない文字を包含している ] `XML$r ◎ A DocumentType node that has an external subset system identifier that contains both a U+0022 QUOTATION MARK (") and a U+0027 APOSTROPHE (') or that contains characters that are not matched by the XML Char production. [XML]
  • ある~nodeの局所~名が, `003A^U `:^smb を包含している。 ◎ A node with a local name containing a U+003A COLON (:).
  • ある~nodeの局所~名が,~XML `Name$P 生成規則に合致していない `XML$r ◎ A node with a local name that does not match the XML Name production. [XML]
  • ある `Attr$I ~nodeが,次を満たしている ⇒ [ どの名前空間にも属さない ]~AND[ その局所~名 ~EQ 文字列 `xmlns^l ] `XMLNS$r ◎ An Attr node with no namespace whose local name is the lowercase string "xmlns". [XMLNS]
  • ある `Element$I ~nodeが複数の属性を有していて,それらの[ 局所~名, 属する名前空間 ]の両者とも互いに同じである。 【属する名前空間が無いものどうしも,属する名前空間は同じと見なされるであろう】 ◎ An Element node with two or more attributes with the same local name and namespace.
  • ある[ `Attr$I / `Text$I / `Comment$I / `ProcessingInstruction$I ]~nodeの~dataが,~XML `Char^P 生成規則に合致しない文字を包含している `XML$r ◎ An Attr node, Text node, Comment node, or ProcessingInstruction node whose data contains characters that are not matched by the XML Char production. [XML]
  • ある `Comment$I ~nodeの~dataが,次を満たしている ⇒ [ ~~連続する 2 個の `002D^U `-^smb を包含している ]~OR[ `002D^U `-^smb で終端している ] ◎ A Comment node whose data contains two adjacent U+002D HYPHEN-MINUS characters (-) or ends with such a character.
  • ある `ProcessingInstruction$I ~nodeが ~OR↓ を満たしている: ◎ ↓

    • その~target名は `~ASCII大小無視$で `xml^l に合致する ◎ A ProcessingInstruction node whose target name is an ASCII case-insensitive match for the string "xml".
    • その~target名は `003A^U `:^smb を包含している ◎ A ProcessingInstruction node whose target name contains a U+003A COLON (:).
    • その~dataは 文字列 `?>^l を包含している ◎ A ProcessingInstruction node whose data contains the string "?>".

注記: ~DOMを直列化-不能にする仕方は、 これらに限られる。 ~XMLが課す他のすべての拘束は、 ~DOMにより施行される — 例えば、 `Document$I ~nodeに 2 個の要素を付加するよう試行しても, `HierarchyRequestError$E 例外が投出されることになる。 ◎ These are the only ways to make a DOM unserialisable. The DOM enforces all the other XML constraints; for example, trying to append two elements to a Document node will throw a "HierarchyRequestError" DOMException.

14.4. ~XML素片の構文解析-法

`~XML素片の構文解析~algo@ は、 所与の ( `文脈~要素$V, 文字列 %入力 ) に対し,次を走らす — それは、 ~nodeたちが成す~listを返すか†, `SyntaxError$E 例外を投出する: ◎ The XML fragment parsing algorithm either returns a Document or throws a "SyntaxError" DOMException. Given a string input and a context element context, the algorithm is as follows:

【† 原文には, “`Document$I を返す” と記されているが、[ 実際の記述(この手続きの最後の段)/ `~HTML素片の構文解析~algo@~HTMLparsing#html-fragment-parsing-algorithm$ / 他所( `DOMPARSING$r )における利用 ]と整合していないので修正している。 】

  1. 新たな`~XML構文解析器$を作成する ◎ Create a new XML parser.
  2. `文脈~要素$V の開始~tagに対応している文字列を,`構文解析器に投入する$ — `文脈~要素$V の視野に入る~DOM内の[ すべての名前空間~接頭辞, および 既定の名前空間(もしあれば) ]を宣言した上で: ◎ Feed the parser just created the string corresponding to the start tag of the context element, declaring all the namespace prefixes that are in scope on that element in the DOM, as well as declaring the default namespace (if any) that is in scope on that element in the DOM.

    • 名前空間~接頭辞は、[ それを~~引数に,要素~上の `lookupNamespaceURI()$m ~methodを呼出したとき ~NULL 以外を返すことになる ]ならば,要素の視野に入るとされる。 ◎ A namespace prefix is in scope if the DOM lookupNamespaceURI() method on the element would return a non-null value for that prefix.
    • 既定の名前空間は、[ それを~~引数に,要素~上の `isDefaultNamespace()$m ~methodを呼出したとき ~T を返すことになる ]ような名前空間である。 ◎ The default namespace is the namespace for which the DOM isDefaultNamespace() method on the element would return true.

    注記: 構文解析器には `DOCTYPE^c は渡されない。 したがって,参照される外部~subsetは無いので、 どの実体も認識されないことになる。 ◎ No DOCTYPE is passed to the parser, and therefore no external subset is referenced, and therefore no entities will be recognized.

  3. %入力 を`構文解析器に投入する$ ◎ Feed the parser just created the string input.
  4. `文脈~要素$V の終了~tagに対応している文字列を,`構文解析器に投入する$ ◎ Feed the parser just created the string corresponding to the end tag of the context element.
  5. ~IF[ ~XML整形式性~errorがある ]~OR[ ~XML名前空間~整形式性~errorがある ] ⇒ ~THROW `SyntaxError$E ◎ If there is an XML well-formedness or XML namespace well-formedness error, then throw a "SyntaxError" DOMException.
  6. ~IF[ 結果の`文書$の`文書~要素$に他の同胞~nodeがある ] ⇒ ~THROW `SyntaxError$E ◎ If the document element of the resulting Document has any sibling nodes, then throw a "SyntaxError" DOMException.
  7. ~RET 結果の`文書$の`文書~要素$の子~nodeたちが成す,`~tree順序$による~list ◎ Return the child nodes of the document element of the resulting Document, in tree order.