0

I use cql_filter to find input values but an error occurs:

Uncaught (in promise) SyntaxError: Unexpected token '<', "<?xml vers"... is not valid JSON

This is error message in XML:

<?xml version="1.0" ?>
<ServiceExceptionReport
version="1.2.0"
xmlns="http://www.opengis.net/ogc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.opengis.net/ogc 
http://schemas.opengis.net/wfs/1.0.0/OGC-exception.xsd">
<ServiceException>
  Could not parse CQL filter list.
Lexical error at line 1, column 13.  Encountered: &quot;\u1ead&quot; (7853), after : &quot;&quot; Parsing : quanhuyen=Qu?n G� V?p;xaphuong=Ph??ng 1;shthua=1;shbando=9.
</ServiceException></ServiceExceptionReport>

And this is URL for fetched:

http://localhost:8081/geoserver/vietnam/ows?service=WFS&version=1.0.0&request=GetFeature&typeName=vietnam%3Ahtgovap&cql_filter=quanhuyen='+quanGet+';xaphuong='+phuongGet+';shthua='+sothuaGet+';shbando='+sotoGet+'&outputFormat=application%2Fjson&q=

Here is the code I use sql_filter:

        var sothuaMap = document.getElementById('sothuaMap');
        var sotoMap = document.getElementById('sotoMap');
        var phuongMap = document.getElementById('phuongMap');
        var quanMap = document.getElementById('quanMap');
        var resultSpan = document.getElementById('span');
        var searchButton = document.getElementById('search');

        function searching(sothuaGet, sotoGet, phuongGet, quanGet) {
        resultSpan.innerHTML = 'Đang tìm thông tin...';
        fetch('http://localhost:8081/geoserver/vietnam/ows?service=WFS&version=1.0.0&request=GetFeature&typeName=vietnam%3Ahtgovap&cql_filter=quanhuyen='+quanGet+';xaphuong='+phuongGet+';shthua='+sothuaGet+';shbando='+sotoGet+'&outputFormat=application%2Fjson&q='  + quanGet +  phuongGet + sothuaGet + sotoGet)
          .then(function (response) {
            return response.json();
          })
          .then(function (json) {
            var results = json.features;
            ....

I have looked and consulted many related questions and issues but none seem to be suitable for my problem.

2
  • You have an XML document returned and are trying to parse it as JSON. Look at the error message in the XML and add that to your question along with the full URL being feteched
    – Ian Turton
    Sep 7, 2022 at 10:21
  • @IanTurton I'm updated my question. Please reopen my question. Thanks you.
    – Jayzz
    Sep 7, 2022 at 10:29

2 Answers 2

2

The error message seems clear enough:

<ServiceException>
  Could not parse CQL filter list.
Lexical error at line 1, column 13.  Encountered: &quot;\u1ead&quot; (7853), after : &quot;&quot; Parsing : quanhuyen=Qu?n G� V?p;xaphuong=Ph??ng 1;shthua=1;shbando=9.
</ServiceException>

Basically, quanhuyen=Qu?n G� V?p;xaphuong=Ph??ng 1;shthua=1;shbando=9. is not a valid string. The most likely issue is that you need to URL encode your query strings before you send them to GeoServer.

It is also not a valid CQL query if you want to combine the 4 queries then you need to use AND or OR (as explained in How to use UNION ALL in GeoServer CQL Filter?)

1
  • Thank you so much, you are a genius.
    – Jayzz
    Sep 8, 2022 at 3:54
0

Saw this error as a result of a data input error. User had input a datetime with 0222 as the year, not 2022. As a result the interpreted datetime value was truncated (the leading zero was removed) so was 13 characters, not 14. When trying to interpret the time portion, 359590 was used, instead of 235959 (must have used an offset to calculate). Amending the year to 2022 resolved the problem.

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.