Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QXmlQuery setquery for kml file
Forum Updated to NodeBB v4.3 + New Features

QXmlQuery setquery for kml file

Scheduled Pinned Locked Moved Unsolved General and Desktop
9 Posts 4 Posters 2.6k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • saitejS Offline
    saitejS Offline
    saitej
    wrote on last edited by
    #1

    What should be the query to get the coordinates in the kml file?

    1 Reply Last reply
    0
    • jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      kml is XML as far as I know. So, you can open it in a text editor and see how/where coordinates are stored and then define the query.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      the_T 1 Reply Last reply
      1
      • jsulmJ jsulm

        kml is XML as far as I know. So, you can open it in a text editor and see how/where coordinates are stored and then define the query.

        the_T Offline
        the_T Offline
        the_
        wrote on last edited by
        #3

        @jsulm
        Yes it is XML Structure, All coordinates can be found between <coordinates> and </coordinates> with a Long/Lat pair in each line.

        -- No support in PM --

        1 Reply Last reply
        2
        • mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by mrjj
          #4

          hi
          This might be interersting to read
          http://stackoverflow.com/questions/9675907/how-can-i-use-qts-qxmlquery-to-run-xpath-queries-on-a-local-file

          it seems your sample has coordinates under LineString

          so something like
          query.setQuery("kml/Document/Placemark[last()]/LineString/coordinates");

          saitejS 1 Reply Last reply
          2
          • mrjjM mrjj

            hi
            This might be interersting to read
            http://stackoverflow.com/questions/9675907/how-can-i-use-qts-qxmlquery-to-run-xpath-queries-on-a-local-file

            it seems your sample has coordinates under LineString

            so something like
            query.setQuery("kml/Document/Placemark[last()]/LineString/coordinates");

            saitejS Offline
            saitejS Offline
            saitej
            wrote on last edited by
            #5

            @mrjj

            I had checked that link before posting but I didn’ understand how the query args are written and it didn't work for my file. So I want to know how the args are written?

                query.setQuery("declare default element namespace \"http://earth.google.com/kml/2.0\"; declare variable $kmlFile external; doc($kmlFile)/kml/Document/Placemark[last()]/LineString/coordinates/text()");
            
            

            Why dis doesn't work?

            1 Reply Last reply
            0
            • mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by mrjj
              #6

              @saitej said:

              text()
              ..]/LineString/coordinates/text()")

              what is that ?
              seems wrong.

              and you should check with
              QString result;
              query.evaluateTo(&result);
              qDebug() << result;

              what you get.

              -how the args are written?
              Sorry. Dont understand what u mean with that.

              1 Reply Last reply
              0
              • saitejS Offline
                saitejS Offline
                saitej
                wrote on last edited by saitej
                #7

                @mrjj
                The result gives me "\n".

                I meant that for any xml file, by knowing the tags and the values you want to access, how to write a query.
                is this part necessary in the query

                "declare default element namespace \"http://earth.google.com/kml/2.0\"; declare variable $kmlFile external; 
                

                or I can start the query with doc($kmlFile)/kml where $kmlFile is the filename

                mrjjM 1 Reply Last reply
                0
                • saitejS saitej

                  @mrjj
                  The result gives me "\n".

                  I meant that for any xml file, by knowing the tags and the values you want to access, how to write a query.
                  is this part necessary in the query

                  "declare default element namespace \"http://earth.google.com/kml/2.0\"; declare variable $kmlFile external; 
                  

                  or I can start the query with doc($kmlFile)/kml where $kmlFile is the filename

                  mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @saitej
                  Ok, so u are getting close. :)

                  To use it , you must learn the syntax and the class
                  https://www.w3.org/TR/xquery/
                  http://doc.qt.io/qt-5/qxmlquery.html

                  saitejS 1 Reply Last reply
                  0
                  • mrjjM mrjj

                    @saitej
                    Ok, so u are getting close. :)

                    To use it , you must learn the syntax and the class
                    https://www.w3.org/TR/xquery/
                    http://doc.qt.io/qt-5/qxmlquery.html

                    saitejS Offline
                    saitejS Offline
                    saitej
                    wrote on last edited by
                    #9

                    @mrjj

                    From what I have understood I have made this query.

                    QXmlQuery query;
                        query.bindVariable("kmlFile", &file);
                        QString q = "declare variable $kmlFile external;doc($kmlFile)/kml/Document/Placemark/LineString/coordinates/text()";
                    
                     query.setQuery(q);
                    

                    But I still get the result value as "\n"

                    1 Reply Last reply
                    0

                    • Login

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved