テクノロジー · 実用ガイド

ElementTree の「unbound prefix」?XML 修復前に namespace を証明する

元 byte を保存し、壊れた完全 document と祖先 scope から切り離された fragment を区別します。権威ある URI がある場合だけ binding を注入します。

Original diagram distinguishing a malformed full XML document from a fragment detached from an ancestor namespace declaration.
オリジナルイラスト:完全 document と detached fragment の scope loss を区別。 Watch at Ease

ElementTree は qualified name の prefix に scope 内 declaration がないと unbound prefix を返します。同じ error は無効な完全 document と、祖先 xmlns を失った有効 fragment の両方で起きます。

URI を推測せず register_namespace() を parse 修復に使いません。完全 document、schema、producer contract、祖先から binding を証明し、memory wrapper にだけ追加して expanded name、attribute、text、tail、manifest を検証します。

修復前に証拠を保存

元 byte を hash し、parser、Python version、line/column、prefix を記録します。

fragment boundary を明示し、producer の無効 document と混同しません。

scope loss を分類

完全 document と ancestor の xmlns を調べ、権威ある URI だけ復元します。

同じ prefix spelling は同じ URI の証拠ではありません。

parse・query・serialization を分離

register_namespace() は出力、find() map は query 用で、malformed input を直しません。

URI が証明済みなら memory wrapper に一つだけ declaration を追加します。

broad recovery を隔離

tolerant parser は tag を閉じたり token を捨てたりするため forensic extraction に限定します。

変更が証明済み binding を超えたら acceptance を失敗させます。

semantic identity で受入

{URI}local、attribute、node count、text、tail、identifier を assertion します。

source digest、URI source、transformation、diagnostic、result を保存します。

Original acceptance diagram that verifies expanded names, attributes, text, tail content, and a bounded repair manifest.
オリジナルイラスト:parse 後に expanded name と内容を検証。 Watch at Ease