とらりもんHOME  Index  Search  Changes  Login

とらりもん - XML Diff

  • Added parts are displayed like this.
  • Deleted parts are displayed like this.

!read attribute from a XML file

!! normal way
$ xmllint --xpath "/isd/IMD/VERSION/text()" 15FEB02013019-M2AS-057363650020_01_P001.XML

!! GPX file (GPS track log)

In case following file named activity_9413397928.gpx:
<?xml version="1.0" encoding="UTF-8"?>
<gpx creator="Garmin Connect" version="1.1"
   xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/11.xsd"
   xmlns:ns3="http://www.garmin.com/xmlschemas/TrackPointExtension/v1"
   xmlns="http://www.topografix.com/GPX/1/1"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ns2="http://www.garmin.com/xmlschemas/GpxExtensions/v3">
   <metadata>
     <link href="connect.garmin.com">
       <text>Garmin Connect</text>
     </link>
     <time>2022-08-16T05:03:57.000Z</time>
   </metadata>
   <trk>
    <name>つくば市 バイク</name>
    <type>cycling</type>
    <trkseg>
      <trkpt lat="36.08374455012381076812744140625" lon="140.1167897880077362060546875">
        <ele>27.799999237060546875</ele>
        <time>2022-08-16T05:03:57.000Z</time>
        <extensions>
...
You can read time by:
$ xmllint --xpath "//*[local-name()='metadata']/*[local-name()='time']/text()" activity_9413397928.gpx
2022-08-16T05:03:57.000Z
You can read name by:
$ xmllint --xpath "//*[local-name()='trk']/*[local-name()='name']/text()" activity_9413397928.gpx
つくば市 バイク
You can get many "time" data by:
$ xmllint --xpath "///*[local-name()='time']/text()" activity_9413397928.gpx | head
2022-08-16T05:03:57.000Z
2022-08-16T05:03:57.000Z
2022-08-16T05:03:58.000Z
2022-08-16T05:04:03.000Z
...


reference: [[https://stackoverflow.com/questions/70756775/xmllint-returns-xpath-set-is-empty]]