QXmlQuery setquery for kml file
-
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.
-
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-fileit seems your sample has coordinates under LineString
so something like
query.setQuery("kml/Document/Placemark[last()]/LineString/coordinates"); -
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?
-
@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. -
@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
-
@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 -
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"