水無月ばけらのえび日記

bakera.jp > 水無月ばけらのえび日記 > 実は valid な HTML::Template

実は valid な HTML::Template

2002年2月18日(月曜日)

実は valid な HTML::Template

HTML::Templateモジュールのドキュメント (www.perldoc.com)に、こんなことが書かれています。

Note: even though these tags look like HTML they are a little different in a couple of ways. First, they must appear entirely on one line. Second, they're allowed to "break the rules". Something like:

<IMG SRC="<TMPL_VAR NAME=IMAGE_SRC>">

is not really valid HTML, but it is a perfectly valid use and will work as planned.

以上、http://www.perldoc.com/perl5.6.1/lib/HTML/Template.html より

not really valid とありますが、そんなことはありません。属性値に "<" と ">" が含まれていることを問題にしているのでしょうが、引用符で括られた属性値は RCDATA としてパースされるので、< などが出現してもマークとはみなされないのです。RFC1866 の 3.2.4. Attributes にも以下のように書かれていました。

NOTE - Some historical implementations consider any occurrence of the `>' character to signal the end of a tag. For compatibility with such implementations, when `>' appears in an attribute value, it should be represented with a numeric character reference. For example, `<IMG SRC="eq1.jpg" alt="a>b">' should be written `<IMG SRC="eq1.jpg" alt="a&#62;b">' or `<IMG SRC="eq1.jpg" alt="a&gt;b">'.

以上、urn:ietf:rfc:1866 より

仕様的には、属性値の中で > を使っても開始タグ終了区切り子とはみなさないことが分かります。

ということで、そのようなマーク付けは実は valid なのです。もちろん、RFC1866 に書いてあった通りオススメできない書き方ではありますし、XML では

[10] AttValue ::= '"' ([^<&"] | Reference)* '"' | "'" ([^<&'] | Reference)* "'"

以上、http://www.w3.org/TR/2000/REC-xml-20001006#NT-AttValue より

ですので、XHTML では invalid となります。

※なお、<IMG SRC="<TMPL_VAR NAME="IMAGE_SRC">"> と書くと、HTML 的にも valid ではなくなります。

関連する話題: HTML / XHTML / XML / SGML / Perl / RFC

最近の日記

関わった本など