[英]how to return XML with TopBraid Composer SPARQL Web Pages?
I'm learning SWP (SPARQL Web Pages) using TopBraid Composer Maestro Edition and I am able to create a SWP file. 我正在使用TopBraid Composer Maestro Edition学习SWP(SPARQL网页),并且能够创建SWP文件。 This SWP file uses SPARQL to query the sample dataset to return results as HTML. 该SWP文件使用SPARQL查询样本数据集以HTML形式返回结果。 This is the code snippet that I have in my project: 这是我项目中的代码片段:
<!-- 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="<http://topbraid.org/examples/kennedys>"
let:test="{= ui:param('test', xsd:string) }">
<h1>G'day, {= ?test }!</h1>
<ul>
<ui:forEach ui:resultSet="{#
SELECT *
WHERE {
<http://topbraid.org/examples/kennedys#AlfredTucker> ?property ?value .
}
}">
<li>{= ui:label(?value) }</li>
</ui:forEach>
</ul>
</ui:setContext>
This SWP snippet works like a charm and displays what I need. 这个SWP片段的工作原理很吸引人,并显示了我的需求。 How can I get XML instead of HTML, though? 但是,如何获取XML而不是HTML?
Edit: 编辑:
This is the HTML that is returned: 这是返回的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>
Instead of that, I just want it to return this with xml headers as well: 取而代之的是,我只希望它也返回带有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 is a data templating tool just like JSP, ASP, etc. The processor will respond with whatever text is in the SWP file unless there is a SWP processing directive, denoted by the curly brackets or a SWP element. SWP是一种数据模板工具,就像JSP,ASP等一样。处理器将以SWP文件中的任何文本进行响应,除非存在用大括号或SWP元素表示的SWP处理指令。 Therefore the short answer to your question is to simply use the XML tags instead of HTML. 因此,对您的问题的简短答案是仅使用XML标记而不是HTML。
The following should give you the XML you're looking for: 以下内容将为您提供所需的XML:
<ui:setContext xmlns:kennedys="http://topbraid.org/examples/kennedys#"
ui:queryGraph="<http://topbraid.org/examples/kennedys>">
<data>
<ui:forEach ui:resultSet="{#
SELECT *
WHERE {
<http://topbraid.org/examples/kennedys#AlfredTucker> ?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.