Linux Bash XMLLINT with XPATH

后端 未结 3 742
孤独总比滥情好
孤独总比滥情好 2020-12-31 05:17

Today I get to learn how to use xmllint properly. It does not seem to be well covered or explained. I plan to use a single language resource file to run my entire system.

3条回答
  •  误落风尘
    2020-12-31 05:28

    I had the same problem a few minutes ago and saw this post.

    After hacking a bit I found the following solution to extract the city:

    (
    wget 'http://maps.googleapis.com/maps/api/geocode/xml?latlng=53.244921,-2.479539&sensor=true' \
      -O dummy.xml -o /dev/null
    xmllint --format \
      --xpath '/GeocodeResponse/result[type = "postal_town"]/address_component[type = "postal_town"]/short_name/node()' \
      dummy.xml
    )
    

    You nee to specify the correct X-Path to get the desired XML-Tag and then return only the node value.

提交回复
热议问题