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

13.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 the XML and Namespaces in XML specifications. [XML] [XMLNS]

この仕様は、~XMLにて正式に定義されるものを超えるような,構文~levelの要件は何も定義しない。 ◎ 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仕様によれば、~XML処理器が[ ~DOCTYPE内から参照されている外部~DTD~subset ]を処理することは,保証されない。 これは例えば、外部~file内に定義される`実体~参照$を ~XML文書~内の文字に利用することは,安全でないことを意味する( `<^c, `>^c, `&^c, `"^c, `'^c は除いて)。 ◎ According to the XML specification, 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 ').

13.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仕様にて与えられる,[ ~byte/文字 ]たちが成す連なりを `Document$I ~objの中へ対応付ける規則 ]に従う構成子である。 ◎ An XML parser, for the purposes of this specification, is a construct that follows the rules given in the XML specification to map a string of bytes or characters into a Document object.

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

`~XML構文解析器$は、 `Document$I ~objの作成-時に結付けられるか,または 暗黙的に作成される。 ◎ An XML parser is either associated with a Document object when it is created, or creates one implicitly.

次に,この `Document$I は、[ `XML$r 仕様, `XMLNS$r 仕様, `DOM$r 標準 ]による定義に従って,構文解析器に渡された入力の木~構造を表現する~DOM~nodeで拡充され~MUST。 要素を表現する~DOM~nodeを作成するときは、[ 適正な`要素~interface$が作成され,`~custom要素$が正しく設定しておかれる ]ことを確保するため,[ `~tokenから要素を作成-$する~algo, または 適切な~XML~data構造に演算する等価な何か ]が利用され~MUST。 ◎ This Document must then be populated with DOM nodes that represent the tree structure of the input passed to the parser, as defined by the XML specification, the Namespaces in XML specification, and the WHATWG DOM standard. When creating DOM nodes representing elements, the create an element for a token algorithm or some equivalent that operates on appropriate XML datastructures must be used, to ensure the proper element interfaces are created and that custom elements are set up correctly.

~DOM変異~event 【 `MutationEvent$I 】 は、`~XML構文解析器$が `Document$I 木~上に遂行する演算~用には,発火されては~MUST_NOTが,~UAは、[ 要素が個別に付加- / 属性が個別に設定- ]されたかのように動作して,[[ 要素が文書の中へ挿入されたとき/要素の属性が設定されたとき ]に何が起こるかに関する,この仕様~内の各種~規則 ]を誘発させ~MUST。 その際には、`変異~observer$に関する `DOM$r 標準の要件により,変異~observerは発火される参照】 ことになる(変異~eventとは違って)。 `XML$r `XMLNS$r `DOM$r `UIEVENTS$r ◎ DOM mutation events must not fire for the operations that the XML parser performs on the Document's tree, 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 the WHATWG DOM standard's requirements regarding mutation observers mean that mutation observers are fired (unlike mutation events). [XML] [XMLNS] [DOM] [UIEVENTS]

要素の開始tagが構文解析されてから,[ 要素の終了tagが構文解析されるか, 構文解析器が整形式性~errorを検出する ]までの間、~UAは,その要素が`~open要素~stack$内にあるかのように動作し~MUST。 ◎ 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.

注記: これは例えば、 `object$e 要素において,[ その子である `param$e 要素が構文解析される前に,~pluginが~instance化される ]のを避けるために利用される。 ◎ This is used, e.g. by the object element to avoid instantiating plugins before the param element children have been parsed.

この仕様は、~UAが外部~実体を検索取得するときに利用するべきである,追加の情報を以下に供する: 次の~listに与える~publicIDは、どれも[ この~link先にある~data と等価な内容を表現する~URL† ]に対応する。 (この~URLは、 有名~文字~参照 節 に挙げる一連の名前~用に`実体~宣言$を包含している~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]

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

~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仕様に対する`故意的な違反$ではないが、~XML仕様が課す要件の精神には反する。 その動機は、[ 外部~subsetを取扱うための~network~accessを,~UAに要求する ]ことなく,[ すべての~UAが,実体を相互運用可能な流儀で取扱う ]ことが欲されていることにある。 `XML$r ◎ This is not strictly a violation of the XML specification, but it does contradict the spirit of the XML specification'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~scriptingの~supportは可能化-$された`~XML構文解析器$ %構文解析器 が, `script$e 要素 %script を作成したときは: ◎ When an XML parser with XML scripting support enabled creates a script element,\

注記: `~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を付加し~MUST。 ◎ 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仕様に対する`故意的な違反$である — あいにく,~XMLを公式的に拡張することは、 `template$e 処理に必要な方式ではできないので。 `XML$r ◎ This is a willful violation of the XML specification; unfortunately, XML is not formally extensible in the manner that is needed for template processing. [XML]

`~XML構文解析器$が作成する `Node$I ~objの`~node文書$は、その挿入-先の~nodeの`~node文書$に設定され~MUST。 ◎ 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 個の文字列に面したかのように動作し~MUST。 ◎ 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構文解析器$と同じ規則に従って `構文解析を停止-$し~MUST。 また,`~XML構文解析器$は、`中止-$されることもあるが,それも`~HTML構文解析器$に対するときと同じ仕方で行われ~MUST。 ◎ 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.

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

`Document$I / `Element$I ~nodeを `~XML素片に直列化-@ する~algoは、その~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事例も適用されないならば、次の形による文字列を返さ~MUST: ◎ ↓

両~事例とも,返される文字列は、~XML名前空間整形式である, かつ[ `木~順序$による,当の~nodeに`関連する子~nodeたち$すべてと同型†な直列化 ]で~MUST。 ~UAは、直列化における[ 名前空間~接頭辞/名前空間~宣言 ]を調整してもよい(また,一部の事例では、名前空間整形式~XMLを得るために,~~実際にそうするよう強いられることもある)。 ~UAは、~DOM内の `Text$I ~nodeを表現するときは、普通の~textに文字~参照を混ぜてもよい。 ◎ In both cases, the string returned must be XML namespace-well-formed and must be an isomorphic serialization of all of that node's relevant child nodes, in tree order. 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 ) — この語に技術的に特別な定義があるのかは不明だが、おそらく,直列化した結果を構文解析した結果が元どおりになる( 2 つの文字列を構文解析した結果が同じ~DOMを生産するならば,それらは同型である、という関係に基づく)ことを意味すると思われる。 】

~nodeに `関連する子~nodeたち@ は、次の規則を適用して与えられる: ◎ A node's relevant child nodes are those that apply given the following rules:

`Element$I に対しては、直列化~内のある要素が名前空間を伴わない場合、その要素の視野に入る所で,既定の名前空間が明示的に空~文字列として宣言され~MUST。 (これは `Document$I に対しては適用されない。) `XML$r `XMLNS$r ◎ 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名前空間整形式になる ◎ 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部分木~内に次のいずれかに該当する~error事例が見出されたときは、~algoは,文字列を返さずに `InvalidStateError$E 例外を投出し~MUST: ◎ 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:

注記: ~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.

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

`~XML素片を構文解析-@ するときは、所与の ( `文脈~要素$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素片を構文解析-$ / 他所における利用 `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[ 結果の `Document$I の`文書~要素$に他の同胞~nodeがある ] ⇒ ~THROW `SyntaxError$E ◎ If the document element of the resulting Document has any sibling nodes, then throw a "SyntaxError" DOMException.
  7. ~RET 結果の `Document$I の`文書~要素$の子~nodeたちが成す,`木~順序$による~list ◎ Return the child nodes of the document element of the resulting Document, in tree order.