Amar
Amar

Reputation: 763

SPARQL Query Exception

I am using APACHE JENA (2.9.4 Version) to fetch the results using SPARQL Query. The below is the code I am using.

public class DataGeneratorTest {

public static void main(String[] args) {

    String query = "PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#> PREFIX owl:<http://dbpedia.org/ontology/> select ?y where { ?x a owl:Person; rdfs:label ?y. FILTER(LANG(?y) = \"en\") } LIMIT 77";
    ResultSet resultSet = SparqlUtil.generate(query);
    ResultSetFormatter.out(System.out, resultSet);

}
}

I have a utility class for executing the sparql query...

public class SparqlUtil {

public static ResultSet generate(String argEndPoint, String argQuery) {
    Precondition.checkNotEmpty(argQuery);
    String endPoint = argEndPoint;
    if (Precondition.checkEmpty(endPoint)) {
        endPoint = SparqlConstants.SPARQL_ENDPOINT;
    }
    QueryExecution queryExecution = null;
    try {
        Query query = QueryFactory.create(argQuery);
        queryExecution = QueryExecutionFactory.sparqlService(endPoint,
                query);
        return queryExecution.execSelect();
    } finally {
        if (Precondition.checkNotNull(queryExecution)) {
            queryExecution.close();
        }
    }
}

public static ResultSet generate(String argQuery) {
    return generate(SparqlConstants.SPARQL_ENDPOINT, argQuery);
}
}

When I run this code I am getting the following exception.

javax.xml.stream.XMLStreamException: ParseError at [row,col]:[40,26]
Message: XML document structures must start and end within the same entity.
at com.sun.org.apache.xerces.internal.impl.XMLStreamReaderImpl.next(Unknown Source)
at    com.hp.hpl.jena.sparql.resultset.XMLInputStAX$ResultSetStAX.getOneSolution(XMLInputStAX.java:435)
at com.hp.hpl.jena.sparql.resultset.XMLInputStAX$ResultSetStAX.hasNext(XMLInputStAX.java:232)
at com.hp.hpl.jena.sparql.resultset.ResultSetMem.<init>(ResultSetMem.java:95)
at com.hp.hpl.jena.sparql.resultset.TextOutput.write(TextOutput.java:147)
at com.hp.hpl.jena.sparql.resultset.TextOutput.write(TextOutput.java:130)
at com.hp.hpl.jena.sparql.resultset.TextOutput.write(TextOutput.java:118)
at com.hp.hpl.jena.sparql.resultset.TextOutput.format(TextOutput.java:65)
at com.hp.hpl.jena.query.ResultSetFormatter.out(ResultSetFormatter.java:122)
at com.hp.hpl.jena.query.ResultSetFormatter.out(ResultSetFormatter.java:74)
at com.data.generator.test.DataGeneratorTest.main(DataGeneratorTest.java:17)
Exception in thread "main" com.hp.hpl.jena.sparql.resultset.ResultSetException: XMLStreamException:     ParseError at [row,col]:[40,26]
Message: XML document structures must start and end within the same entity.
at com.hp.hpl.jena.sparql.resultset.XMLInputStAX$ResultSetStAX.staxError(XMLInputStAX.java:539)
at com.hp.hpl.jena.sparql.resultset.XMLInputStAX$ResultSetStAX.hasNext(XMLInputStAX.java:236)
at com.hp.hpl.jena.sparql.resultset.ResultSetMem.<init>(ResultSetMem.java:95)
at com.hp.hpl.jena.sparql.resultset.TextOutput.write(TextOutput.java:147)
at com.hp.hpl.jena.sparql.resultset.TextOutput.write(TextOutput.java:130)
at com.hp.hpl.jena.sparql.resultset.TextOutput.write(TextOutput.java:118)
at com.hp.hpl.jena.sparql.resultset.TextOutput.format(TextOutput.java:65)
at com.hp.hpl.jena.query.ResultSetFormatter.out(ResultSetFormatter.java:122)
at com.hp.hpl.jena.query.ResultSetFormatter.out(ResultSetFormatter.java:74)
at com.data.generator.test.DataGeneratorTest.main(DataGeneratorTest.java:17)
Caused by: javax.xml.stream.XMLStreamException: ParseError at [row,col]:[40,26]
Message: XML document structures must start and end within the same entity.
at com.sun.org.apache.xerces.internal.impl.XMLStreamReaderImpl.next(Unknown Source)
at     com.hp.hpl.jena.sparql.resultset.XMLInputStAX$ResultSetStAX.getOneSolution(XMLInputStAX.java:435)
at com.hp.hpl.jena.sparql.resultset.XMLInputStAX$ResultSetStAX.hasNext(XMLInputStAX.java:232)
... 8 more

I am trying to retrieve the first 77 results only. When I limit this result set to 76 I was able to fetch the results without any exception but when I increase this limit to 77 I am getting the above exception. There is an issue with the 77th record. How can I overcome this issue. I stuck over here. Can anyone help me on this...???

Thanx in advance, Amar.

Upvotes: 0

Views: 541

Answers (1)

AndyS
AndyS

Reputation: 16700

What is SparqlConstants.SPARQL_ENDPOINT? dbpedia.org has limits on time and truncates the results, leading to illegal XML. That would explain the situation but without knowing what, if anything, the 77th entry is, we can't say.

Upvotes: 1

Related Questions