2013-10-25 66 views
1

我正在使用TopBraid作曲家大师版学习SWP(SPARQL网页),并且我可以创建一个SWP文件。此SWP文件使用SPARQL查询示例数据集以将结果作为HTML返回。这是代码片段,我在我的项目:如何使用TopBraid Composer SPARQL网页返回XML?

<!-- 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> 
+0

什么是你所得到的查询结果?它的格式是什么? (我知道你说过HTML,但是如果是,例如XHTML,那么它也是XML)。 –

+0

我刚刚使用HTML输出编辑原始文章 –

+0

您是否尝试过使用regexp和/或XSLT修剪返回的HTML并返回只有XML? – Xenyal

回答

0

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>