how to return XML with TopBraid Composer SPARQL Web Pages?

169 Views Asked by At

I'm learning SWP (SPARQL Web Pages) using TopBraid Composer Maestro Edition and I am able to create a SWP file. This SWP file uses SPARQL to query the sample dataset to return results as 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="&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>

This SWP snippet works like a charm and displays what I need. How can I get XML instead of HTML, though?

Edit:

This is the HTML that is returned:

<!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:

<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>
1

There are 1 best solutions below

0
On

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. Therefore the short answer to your question is to simply use the XML tags instead of HTML.

The following should give you the XML you're looking for:

<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>