Home
Categories
Dictionary
Download
Project Details
Changes Log
FAQ
License

QueryResults



The QueryResults class allows to decode the XML results of a SPARQL request.

Overview

The result of a SPARQL request can be either: The QueryResultsUtilities class allows to parse the XML and create an associated data structure which can be processed by your program.

queryresults
The various static methods QueryResults instance create a QueryResults instance.

QueryResults class

The QueryResults class has the following methods:
Each result is a QueryResults.Result element.

Results order

The key of the result Map will be the SELECT variable used to order the result (by the orderedBy argument)). If this variable was not part of the SELECT variables, then it will be the first encountered variable in the columns.

QueryResults.Result class

The QueryResults.Result represent one result. It contains the Map of attributes for one result.

This class has the following methods:
Each value is a QueryResults.Value element.

QueryResults.Value class

The QueryResults.Value class represent one value in a result.

This class has the following methods:

Examples

Basic example

Suppose the following query:
   SELECT ?number ?type
   WHERE { 
      ?alarm rdf:type inav:Alarm .
      ?alarm inav:AlarmNumber ?number .
      ?alarm inav:hasAlarmType ?type .
   }    
The following code will print the ?number and ?type of each result:
   public void subscribe(ServiceInstance service) {
      QueryResults results = (QueryResults) service.getData("response").getValue();
      Iterator<QueryResults.Result> it = results.getOrderedResultsList().iterator();
      while (it.hasNext()) {
       QueryResults.Result result = it.next();
        int number = result.getValue("number").getValueAsInt();
        String type = result.getValue("type").getValueAsString();
        System.out.println("Alarm " + number + ": " + type);
      }
   }

Second example

Suppose the following SPARQL XML result:
   <sparql xmlns="http://www.w3.org/2005/sparql-results#">
      <head>
         <variable name="name"/>
         <variable name="age"/>
      </head>
      <results>
         <result> 
            <binding name="name">
               <literal xml:lang="en">Bob</literal>
            </binding>
            <binding name="age">
               <literal datatype="http://www.w3.org/2001/XMLSchema#integer">30</literal>
            </binding>
         </result>
         <result> 
            <binding name="name">
               <literal xml:lang="en">Bobby</literal>
            </binding>
            <binding name="age">
               <literal datatype="http://www.w3.org/2001/XMLSchema#integer">40</literal>
            </binding>
         </result>      
      </results>
   </sparql>
If we call:
   QueryResults results = QueryResultsUtilities.getOrderedResults(<XML String>, true, "name");
Wr will have two results:
  • The first result is the element with the name "Bob"
  • The second result is the element with the name "Bobby"

See also


Categories: Queryresults

Copyright 2025 Dassault Aviation. All Rights Reserved. Documentation and source under the LGPL v3 licence