繁体   English   中英

如何使用TopBraid Composer SPARQL网页返回XML?

[英]how to return XML with TopBraid Composer SPARQL Web Pages?

我正在使用TopBraid Composer Maestro Edition学习SWP(SPARQL网页),并且能够创建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片段的工作原理很吸引人,并显示了我的需求。 但是,如何获取XML而不是HTML?

编辑:

这是返回的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>

SWP是一种数据模板工具,就像JSP,ASP等一样。处理器将以SWP文件中的任何文本进行响应,除非存在用大括号或SWP元素表示的SWP处理指令。 因此,对您的问题的简短答案是仅使用XML标记而不是HTML。

以下内容将为您提供所需的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>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM