跳转至内容

XForms/Adder

来自维基教科书,开放的书籍,开放的世界

该程序演示了从 XForms 应用程序示例调用 Web 服务的几种不同方法。该示例使用 HTTP POST 和 HTTP GET 方法,并展示了结果如何返回到模型中的实例以及如何用结果替换页面。它调用的 Web 服务是一个简单的 Web 服务,它将两个数字加在一起。

屏幕图像

[编辑 | 编辑源代码]
XForms Adder 示例执行后
[编辑 | 编辑源代码]

为了将结果使用 FireFox 放入模型中,请确保将 www.sa.kw.ua.saxforms-examples.google.com 添加到 FireFox 的工具/选项/安全/允许站点菜单中的 XForms 白名单中。这是必需的,因为我们的 Web 表单托管在一个域名上,但 Web 服务托管在另一个域名上。

加载 XForms 应用程序

示例程序

[编辑 | 编辑源代码]
<html
   xmlns="http://www.w3.org/1999/xhtml"
   xmlns:xf="http://www.w3.org/2002/xforms" 
   xmlns:xs="http://www.w3.org/2001/XMLSchema"
   xmlns:ev="http://www.w3.org/2001/xml-events" >
    <head>
        <title>XQuery Tester</title>
        <style type="text/css">
            @namespace xf url("http://www.w3.org/2002/xforms");        
            body {font-family: Arial,sans-serif;}
            
            xf|input, xf|output {
               display: table-row;
               line-height: 2em;
            }
            
            xf|label {
               display: table-cell;
               text-align: right;
               font-family: Arial, Helvetica, sans-serif;
               font-weight: bold;
               font-size: small;
               padding-right: 5px;
               width: 150px;
            }  
        </style>
        <xf:model>
            <xf:instance xmlns="" id="input-parameters">
                <data>
                    <arg1>123</arg1>
                    <arg2>456</arg2>
                </data>
            </xf:instance>
            <xf:instance xmlns="" id="submit-results">
                <results>
                    <sum/>
                </results>
            </xf:instance>
            
            <xf:submission id="get-instance" method="get" replace="instance" instance="submit-results"
                action="http://www.cems.uwe.ac.uk/xmldb/rest/db/Wiki/adder.xq"
                separator="&amp;">
                <xf:toggle case="case-busy" ev:event="xforms-submit"/>
                <xf:toggle case="case-submit-error" ev:event="xforms-submit-error"/>
                <xf:toggle case="case-submit-done" ev:event="xforms-submit-done"/>
            </xf:submission>          
            
            <xf:submission id="get-replace" method="get" replace="all" instance="submit-results"
                action="http://www.cems.uwe.ac.uk/xmldb/rest/db/Wiki/adder.xq"
                separator="&amp;">
                <xf:toggle case="case-busy" ev:event="xforms-submit"/>
                <xf:toggle case="case-submit-error" ev:event="xforms-submit-error"/>
                <xf:toggle case="case-submit-done" ev:event="xforms-submit-done"/>
            </xf:submission>
            
            <xf:submission id="post-instance" method="post" 
                replace="instance" instance="submit-results" 
                action="http://www.cems.uwe.ac.uk/xmldb/rest/db/Wiki/adder-post.xq">
                <xf:toggle case="case-busy" ev:event="xforms-submit"/>
                <xf:toggle case="case-submit-error" ev:event="xforms-submit-error"/>
                <xf:toggle case="case-submit-done" ev:event="xforms-submit-done"/>
            </xf:submission>
            
            <xf:submission id="post-replace" method="post"
                action="http://www.cems.uwe.ac.uk/xmldb/rest/db/Wiki/adder-post.xq">
                <xf:toggle case="case-busy" ev:event="xforms-submit"/>
                <xf:toggle case="case-submit-error" ev:event="xforms-submit-error"/>
                <xf:toggle case="case-submit-done" ev:event="xforms-submit-done"/>
            </xf:submission>
            
            <xf:submission id="get-test" method="get" replace="all" 
                separator="&amp;"
                action="http://xformstest.org/cgi-bin/showinstance.sh"/>
            
            <xf:submission id="post-test" method="post" replace="all" 
                action="http://xformstest.org/cgi-bin/showinstance.sh"/>
        </xf:model>
    </head>
    <body>
        <h1>Using XForms to test XQuery</h1>
        <p>Note, you must have xforms-examples.googlecode.com and www.cems.uwe.ac.uk in your whitelist for this demo to work.</p>
       
        <xf:input ref="arg1" incremental="true">
            <xf:label>Arg1:</xf:label>
        </xf:input>
        <xf:input ref="arg2" incremental="true">
            <xf:label>Arg2:</xf:label>
        </xf:input>
        
        <xf:output ref="instance('submit-results')/sum">
            <xf:label>Sum:</xf:label>
        </xf:output>
        
        <xf:submit submission="get-instance">
            <xf:label>HTTP GET -> instance</xf:label>
        </xf:submit>
        <br/>
        
        <xf:submit submission="post-instance">
            <xf:label>HTTP POST -> instance</xf:label>
        </xf:submit>
        <br/>
        
        <xf:submit submission="get-replace">
            <xf:label>HTTP GET -> replace</xf:label>
        </xf:submit>
        <br/>
        
        <xf:submit submission="post-replace">
            <xf:label>HTTP POST -> replace</xf:label>
        </xf:submit>
        <br/>
        
        <xf:submit submission="get-test">
            <xf:label>HTTP Get Test</xf:label>
        </xf:submit>
        <br/>
        <xf:submit submission="post-test">
            <xf:label>HTTP Post Test</xf:label>
        </xf:submit>
        <br/>
        
        <xf:switch>
            <xf:case id="ready"/>
            <xf:case id="case-busy">
                <p>Waiting for results from server...</p>
            </xf:case>
            <xf:case id="case-submit-error">
                <p>Submit error</p>
            </xf:case>
            <xf:case id="case-submit-done">
                <p>Submit done</p>
            </xf:case>
        </xf:switch>
    </body>
</html>
下一页: 输入 | 上一页: 绑定
首页: XForms
华夏公益教科书