js-xml - JavaScriptを用いたXMLの省略記法

手抜き解説

最終更新
2003-11-30T15:07:38+09:00

実はjs-htmlと殆ど同じです。違いは次の二つです。

  • keyは必ずStringリテラルで書く
  • イベントハンドラを定義できない

QNameは、名前空間接頭辞:ローカル名 の形式を取ることがあり、JavaScriptのObjectリテラルの構文に引っかかります。また、JavaScriptのKeywordや、FutureReservedWordとのバッティングを避けるためにも、必ずkeyはStringリテラルで書きます。

var infoset = {"rdf:Description": null, $attrs: {"rdf:about": "http://"}}

参考のためKeywordとFutureReservedWord(予約語)を挙げておきます。ECMAScript Language Specification 3rd edition (PDF) より抜粋。

Keyword
break, else, new, var, case, finally, return, void, catch, for, switch, while, continue, function, this, with, default, if, throw, delete, in, try, do, instanceof, typeof
FutureReservedWord
abstruct, enum, int, short, boolean, export, interface, static, byte, extends, long, super, char, final, native, synchronized, class, float, package, throws, const, goto, private, transient, debugger, implements, protected, volatile, double, import, public

実装例

最終更新
2003-11-30T12:25:51+09:00

XMLBuilderで js-xml を具体的なXMLドキュメントの断片に変換できます。