Why does this XPath expression not return the correct value in xmlstarlet?

前端 未结 1 1171
闹比i
闹比i 2021-01-07 10:12

I\'m trying to extract the contents of the \'coordinates\' node in this KML file using xmlstarlet.

The KML file validates fine using xmlstarlet itself.

I\'ve

相关标签:
1条回答
  • 2021-01-07 10:51

    You need to define and use a namespace prefix for http://earth.google.com/kml/2.2 test.kml - something like this:

    xmlstarlet sel -t -c "//kml:coordinates/text()" -N kml=http://earth.google.com/kml/2.2 test.kml
    

    XPaths do not have a default namespace - if a name in a XPath does not specify a namespace prefix it is assumed to be in the null namespace; hence it is necessary to always specify a namespace prefix when trying to match nodes whose names are in a namespace different from the null one (as in this case).

    0 讨论(0)
提交回复
热议问题