1

TopBraid Composer Maestro Edition を使用して SWP (SPARQL Web ページ) を学習しており、SWP ファイルを作成できます。この SWP ファイルは、SPARQL を使用してサンプル データセットにクエリを実行し、結果を HTML として返します。これは、私のプロジェクトにあるコード スニペットです。

<!-- Navigate to http://localhost:8083/tbl/tutorial.swp?test=Mate in a web browser -->
<ui:setContext 
    xmlns:kennedys="http://topbraid.org/examples/kennedys#"
    ui:queryGraph="&lt;http://topbraid.org/examples/kennedys&gt;"
        let:test="{= ui:param('test', xsd:string) }">
        <h1>G'day, {= ?test }!</h1>
        <ul>
            <ui:forEach ui:resultSet="{#
                SELECT * 
                WHERE {
                    &lt;http://topbraid.org/examples/kennedys#AlfredTucker&gt; ?property ?value .
                }
                }">
            <li>{= ui:label(?value) }</li>
        </ui:forEach>
    </ul>
</ui:setContext>

この SWP スニペットは魔法のように機能し、必要なものが表示されます。HTML ではなく XML を取得するにはどうすればよいでしょうか。

編集:

返される HTML は次のとおりです。

<!DOCTYPE html>
<html>
    <head>
        <META http-equiv="Content-Type" content="text/html; charset=utf-8">
    </head>
    <body>
        <data>
            <entry>
                <property>year of birth</property>
                <value>1967</value>
            </entry>
            <entry>
                <property>first name</property>
                <value>Alfred</value>
            </entry>
            <entry>
                <property>has gender</property>
                <value>male</value>
            </entry>
            <entry>
                <property>last name</property>
                <value>Tucker</value>
            </entry>
            <entry>
                <property>name</property>
                <value>Alfred Tucker</value>
            </entry>
            <entry>
                <property>has spouse</property>
                <value>Kym Smith</value>
            </entry>
            <entry>
                <property>http://www.w3.org/1999/02/22-rdf-syntax-ns#type</property>
                <value>Person</value>
            </entry>
        </data>
    </body>
</html>

その代わりに、これを xml ヘッダーと共に返すようにしたいだけです。

<data>
  <entry>
    <property>year of birth</property>
    <value>1967</value>
  </entry>
  <entry>
    <property>first name</property>
    <value>Alfred</value>
  </entry>
  <entry>
    <property>has gender</property>
    <value>male</value>
  </entry>
  <entry>
    <property>last name</property>
    <value>Tucker</value>
  </entry>
  <entry>
    <property>name</property>
    <value>Alfred Tucker</value>
  </entry>
  <entry>
    <property>has spouse</property>
    <value>Kym Smith</value>
  </entry>
  <entry>
    <property>http://www.w3.org/1999/02/22-rdf-syntax-ns#type</property>
    <value>Person</value>
  </entry>
</data>
4

1 に答える 1

0

SWP は、JSP や ASP などと同様のデータ テンプレート ツールです。プロセッサは、中括弧または SWP 要素で示される SWP 処理ディレクティブがない限り、SWP ファイル内のテキストに応答します。したがって、あなたの質問に対する簡単な答えは、HTML の代わりに XML タグを使用することです。

以下は、探している XML を提供するはずです。

<ui:setContext xmlns:kennedys="http://topbraid.org/examples/kennedys#"
               ui:queryGraph="&lt;http://topbraid.org/examples/kennedys&gt;">
    <data>
        <ui:forEach ui:resultSet="{#
            SELECT * 
            WHERE {
                &lt;http://topbraid.org/examples/kennedys#AlfredTucker&gt; ?property ?value .
            }
            }">
           <entry>
              <property>{= ?property}</property>
              <value>{= ui:label(?value) }</value>
           </entry>
       </ui:forEach>
    </data>
</ui:setContext>
于 2016-03-17T16:15:25.367 に答える