跳轉到內容

XRX/元資料購物者

來自華夏公益教科書,開放世界開放書籍
< XRX

您希望允許非程式設計師(業務分析師、專案經理、業務部門、主題專家等)能夠從元資料登錄檔中建立精確的資料元素列表。此工具具有一個搜尋功能,允許這些使用者查詢資料元素,然後將它們新增到可以儲存以供將來使用的列表中。此列表(稱為願望清單)然後可以用來生成子模式,這些子模式被匯入 XML 交換文件中。

元資料購物者是允許非程式設計師建立精確的資料交換規範的關鍵工具之一。任何接受過幾小時培訓的人現在都可以建立精確的資料元素列表,這些元素在語義上與其他資料交換一致。一般來說,購物車幫助使用者找到資料交換樹上的“葉子”。這些元素的確切順序、哪些元素是必需的、巢狀結構以及交換中元素的數量通常不被認為是元資料購物過程的一部分。這些被認為是資料交換的“約束”,而不是資料交換的語義。語義由願望清單驅動,約束通常包含在交換的 XML 模式中。

這種將資料交換的語義與交換的約束分離的模式被稱為關注點分離,是允許非程式設計師更多參與建立資料交換流程的主要驅動力之一。

我們將建立一個 XForms 應用程式,它有兩個“提交”元素。一個用於獲取搜尋結果,另一個用於儲存願望清單。當用戶看到他們想要保留的搜尋結果時,它將被新增到願望清單中。在會話結束時,使用者通常會將他們的願望清單儲存在願望清單登錄檔中。

此程式建立的願望清單旨在用於子模式生成器,該生成器將在本書後面討論。

螢幕截圖

[編輯 | 編輯原始碼]

這是一個在您開始搜尋資料元素之前購物車樣例螢幕截圖

空購物車

這是在搜尋欄位中輸入“姓氏”等搜尋詞並獲得單個命中後的結果。獲得此命中後,您可以單擊新增按鈕並觀察結果新增到右側的願望清單中。

搜尋“last”的結果

這是一個示例螢幕截圖,顯示了在將幾個元資料元素新增到購物車之後的樣子。

滿購物車

資料元素搜尋結果

[編輯 | 編輯原始碼]

元資料購物者依賴於資料元素搜尋服務,該服務將返回與查詢匹配的資料元素列表。

例如,如果資料元素查詢的 URL 為以下內容

BASENAME/search/search.xq?q=birth

結果集的格式如下

<results>
   <DataElement>
      <DataElementName>PersonBirthDate</DataElementName>
      <NamespaceURI>http://www.example.com/registry<NamespaceURI>
      <DataElementDefinitionText>The date a person was born.</DataElementDefinitionText>
    </DataElement>
    <DataElement>
       <DataElementName>PersonGivenName</DataElementName>
       <NamespaceURI>http://www.example.com/registry<NamespaceURI>
       <DataElementDefinitionText>The name given to a person at birth.  Also referred to as a first name in western cultures.</DataElementDefinitionText>
    </DataElement>
</results>

在將搜尋提交發送到伺服器後,搜尋結果會返回並自動填充表單中的搜尋結果例項。這是在不重新載入表單的情況下完成的。

程式原始碼

[編輯 | 編輯原始碼]

以下 XQuery 動態生成一個 XForms 應用程式。我們使用 XQuery 生成表單,因為我們經常希望使用預設願望清單對其進行引數化。

xquery version "1.0";

declare option exist:serialize "method=xml media-type=text/xml indent=yes";

let $title := 'Basic Metadata Shopper Version 1'

return
<html
   xmlns="http://www.w3.org/1999/xhtml"
   xmlns:xf="http://www.w3.org/2002/xforms" 
   xmlns:ev="http://www.w3.org/2001/xml-events">
    <head>
        <title>{$title}</title>
        <link rel="stylesheet" type="text/css" href="shopping-cart.css"/>
        <xf:model>
            <!-- here is where you store the search query before you hit the "search button". -->
            <xf:instance xmlns="" id="search-criteria">
                <data>
                    <q/>
                </data>
            </xf:instance>
            <xf:instance xmlns="" id="shopping-cart">
                <data>
                    <FileName>test.xml</FileName>
                    <!-- Thing from the OWN namespace -->
                    <DataElement>
                        <DataElementName>Thing</DataElementName>
                        <NamespaceURI>http://www.w3.org/2002/07/owl</NamespaceURI>
                        <definition>The root of all data elements.</definition>
                    </DataElement>
                </data>
            </xf:instance>
            <xf:instance xmlns="" id="search-response">
                <data/>
            </xf:instance>
            <xf:instance xmlns="" id="save-wantlist-response">
                <data/>
            </xf:instance>
            <xf:submission id="search" ref="instance('search-criteria')" method="get" action="search-elements.xq" replace="instance" instance="search-response" 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-done" ev:event="xforms-submit-done"/>
            </xf:submission>
            <xf:submission id="save-wantlist" ref="instance('shopping-cart')" method="post" action="../edit/save-new.xq" replace="instance" instance="save-wantlist-response" separator="&amp;">
                <xf:toggle case="save-wantlist-case-busy" ev:event="xforms-submit"/>
                <xf:toggle case="save-wantlist-case-submit-error" ev:event="xforms-submit-error"/>
                <xf:toggle case="save-wantlist-case-done" ev:event="xforms-submit-done"/>
            </xf:submission>
            <!-- just for testing if you don't have an instance inspector in the browser like XForms buddy -->
            <xf:submission id="echo-search-criteria" ref="instance('search-criteria')" method="post" action="../xqueries/echo-test.xq" replace="all"/>
            <xf:submission id="echo-wantlist" ref="instance('shopping-cart')" method="post" action="../xqueries/echo-test.xq" replace="all"/>
        </xf:model>
    </head>
    <body>
        <a class="breadcrumb" href="../index.xhtml">Metadata Registry Home</a> &gt;
        <a class="breadcrumb" href="index.xhtml">Shopping Cart Home</a>
      
        <div class="search">
            <h1>Metadata Shopper</h1>
            <xf:input ref="instance('search-criteria')/string" incremental="true">
                <xf:label>Search:</xf:label>
            </xf:input>
            <xf:submit submission="search">
                <xf:label>Search</xf:label>
            </xf:submit>
            <xf:switch>
                <xf:case id="ready">
                    <!-- <xf:submit submission="echo-search-criteria">
                        <xf:label>Echo Search Criteria</xf:label>
                    </xf:submit> -->
                </xf:case>
                <xf:case id="case-busy">
                    <p>Waiting for response...</p>
                </xf:case>
                <xf:case id="case-submit-error">
                    <p>The server has returned a submit error event.</p>
                </xf:case>
                <xf:case id="case-done">
                
                    <div class="search-results">
                    <h3>Search Results:</h3>
                        <xf:repeat id="search-results-repeat" nodeset="instance('search-response')/DataElement">
                        <div class="result">
                             <xf:trigger>
                                <xf:label>Add</xf:label>
                                <xf:action ev:event="DOMActivate">
                                    <xf:insert nodeset="instance('shopping-cart')/DataElement" at="last()" position="after"/>

                                    
                                    <!-- the nth one selected -->
                                    <xf:setvalue ref="instance('debug')/search-index" value="index('search-results-repeat')"/>
                                    <xf:setvalue ref="instance('debug')/item-to-add" value="instance('search-response')/DataElement[index('search-results-repeat')=position()]/DataElementName"/>
                                    
                                    
                                    <!-- set the last element in the cart to the selected item -->
                                    <xf:setvalue ref="instance('shopping-cart')/DataElement[last()]/DataElementName" value="instance('search-response')/DataElement[index('search-results-repeat')=position()]/DataElementName"/>
                                </xf:action>
                            </xf:trigger>
                            <div class="result-text">
                            <b>
                                <xf:output ref="DataElementName"/>
                            </b>
                            <i>
                                <xf:output ref="DataElementDefinitionText/text()"/>
                            </i>
                           </div>
                           </div>
                        </xf:repeat>
                    </div>
                </xf:case>
            </xf:switch>
            <xf:switch>
                <xf:case id="ready"/>
                <xf:case id="save-wantlist-case-busy">
                    <p>Waiting for response...</p>
                </xf:case>
                <xf:case id="save-wantlist-case-submit-error">
                    <p>The server has returned a submit error event.</p>
                </xf:case>
                <xf:case id="save-wantlist-case-done">
                    <div class="search-results">
                        <xf:repeat id="search-results-repeat" nodeset="instance('save-wantlist-response')/results">
                            <xf:output ref="Message/text()"/>
                        </xf:repeat>
                    </div>
                </xf:case>
            </xf:switch>
        </div>
        
          <div class="shopping-cart-sidebar">
            <img src="shopping-cart.jpg" height="50"/>
            <h3>Shopping Cart Contents:</h3>
            <ul>
                <xf:repeat id="shopping-cart-repeat" nodeset="instance('shopping-cart')/DataElement">
                    <li>
                        <xf:output value="concat(prefix,':', DataElementName)" class="url"/>
                        <!-- TODO figure out how to bind an output to a URL&lt;xf:output
                            value="concat(
                            'http://dlficsb501:8080/exist/rest/db/mdr/data-elements/views/view-data-element.xq?id=',
                            DataElementName,
                            prefix,':', DataElementName
                            )"
                        class="url" /&gt; -->
                    </li>
                </xf:repeat>
                <br/>
                <xf:input ref="instance('shopping-cart')/FileName">
                    <xf:label><b>Wantlist name:</b></xf:label>
                </xf:input>
                <xf:submit submission="save-wantlist">
                    <xf:label>Save Wantlist</xf:label>
                </xf:submit>
                <!-- 
                <xf:submit submission="echo-wantlist">
                    <xf:label>Echo Wantlist</xf:label>
                </xf:submit>
                -->
            </ul>
        </div>
    </body>
</html>

您可能還想將多個元素複製到購物車中,例如書名和書的價格。為此,您可以使用 XForms 插入的新“origin”屬性,不僅複製單個元素,而且將整個複雜節點複製到購物車中。


返回: 業務規則模板 下一步: 子模式生成器

華夏公益教科書