user-data に xml 内容を保存する
いまさらながらではあるが、
- https://www.xfytec.com/community/modules/news/article.php?storyid=278#top
> xfy コミュニティ - XVCD プログラミング Tips集 目次
なんてページがあることを知った。
読んでいて思いついたことをメモしておく。
つぎのような記載があったけど、
- https://www.xfytec.com/community/modules/news/article.php?storyid=314#variables
> Q. variableとuser-dataの違いは?
> ... user-dataは何度でも書き換えが可能な変数です。user-dataはテキストデータのみ設定可能です。...
function:dom-to-xml-string / function:xml-string-to-dom をつかって、 string 化したものを user-data に保存するようにすれば、xml データの保存もできるのでは?
実際にためしてみよう。
上2行に variable に保持した xml 断片から生成したもの
下2行に user-data に保持した html 断片(string <-> dom 変換を利用) から生成したものが表示できている。
message-box には user-data に保持している文字列を表示している。
以下に ソースコード(2ファイル) を示す。
2番目のソース中の太字部分が、variable, use-data への値設定の箇所である。
$ cat HelloWorld.xml
<?xml version="1.0"?>
<hw:document xmlns:hw="http://xmlns.example.com/developer/tutorial/helloworld">
<hw:message>
Hello World!
</hw:message>
</hw:document>
$ cat HelloWorld.xvcd
<?xml version="1.0"?>
<xvcd:xvcd
xmlns:xvcd="http://xmlns.xfy.com/xvcd"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:function="http://xmlns.xfy.com/function"
xmlns:instruction="http://xmlns.xfy.com/instruction"
xmlns:ctrl="http://xmlns.xfy.com/controls"
xmlns:hw="http://xmlns.example.com/developer/tutorial/helloworld"
version="1.0">
<xvcd:vocabulary name="HelloWorld" match="hw:document" call-template="root"/>
<xvcd:template name="root">
<html>
<body>
<xvcd:apply-templates/>
</body>
</html>
</xvcd:template>
<xvcd:template match="hw:message">
<xvcd:variable name="val">
<hw:data>
<hw:item>Internet Explorer</hw:item>
<hw:item>Netscape Navigator</hw:item>
</hw:data>
</xvcd:variable>
<xvcd:user-data name="data-text" value="{function:dom-to-xml-string($val)}"/>
value:<br />
<xvcd:for-each select="$val/hw:data/hw:item">
<xvcd:value-of select="."/><br />
</xvcd:for-each>
user-data:<br />
<xvcd:for-each select="function:xml-string-to-dom(xvcd:user-data('data-text'))/hw:data/hw:item">
<xvcd:value-of select="."/><br />
</xvcd:for-each>
<span align="right">
<ctrl:trigger>
<ctrl:label>DEBUG:variable</ctrl:label>
<xvcd:action event="ctrl:triggered" >
<instruction:call name="debug">
<instruction:with-param name="str" select="function:dom-to-xml-string($val)" />
</instruction:call>
</xvcd:action>
</ctrl:trigger>
<ctrl:trigger>
<ctrl:label>DEBUG:user-data</ctrl:label>
<xvcd:action event="ctrl:triggered" >
<instruction:call name="debug">
<instruction:with-param name="str" select="xvcd:user-data('data-text')"/>
</instruction:call>
</xvcd:action>
</ctrl:trigger>
</span>
</xvcd:template>
<xvcd:command name="debug">
<instruction:param name="str"/>
<instruction:message-box>
<xvcd:value-of select="$str"/>
</instruction:message-box>
</xvcd:command>
</xvcd:xvcd>
« jruby のダイアログ | トップページ | ピックアップ:Stanford 大学が Zimbra を全面採用, amazonがXMLDBを採用した理由, etc... »
この記事へのコメントは終了しました。
トラックバック
この記事へのトラックバック一覧です: user-data に xml 内容を保存する:
» xhtml-print.com [xhtml-print.com]
XMLでは大文字・小文字が厳密に区別される。XHTML勧告の場合、要素名・属性名は全て小文字でのみ定義されていることから、
[続きを読む]
« jruby のダイアログ | トップページ | ピックアップ:Stanford 大学が Zimbra を全面採用, amazonがXMLDBを採用した理由, etc... »
コメント