Hi i am not sure if this is possible, i have checked over google many options.

For example if i have a http URL which has xml content : http://server.com/lastBuild/api/xml

content would be something like below and <building>false</building> this can be present in multiple lines

<action/> <building>false</building> <displayName>mercury_system</displayName> <duration>1606128</duration>

Can i parse the same http url without downloading the content to local and print the last occurrence of 'false' string in <building>false</building>?

  • print the last occurrence of 'false' string - just print false? Show the desired output Jun 15 '17 at 15:40
  • @RomanPerekhrest yes, just print the last occurence of 'false' string Jun 15 '17 at 15:41
  • 1
    if it would not be the last it will still be false string. What is the point of printing false? Jun 15 '17 at 15:43
  • Not sure of any cool Command line programs you can use to do this.. But i know a script (python, perl, etc) or something java based (using JDOM) to do this...
    – ryekayo
    Jun 15 '17 at 15:44
  • @RomanPerekhrest oops i missed it, it might be 'false' or 'success'. Need to print the string present in <building>false/success</building> Jun 15 '17 at 15:44

You don't need to 'download' it to a file first. You can temporarily download it as part of a pipeline

Use xmlstarlet to parse xml

curl 'http://example.com/lastBuild/api/xml' 
| xmlstarlet sel -t -c "//building[last()]/text()"

Sed alternative:

$ curl -s 'https://raw.githubusercontent.com/gevasiliou/PythonTests/master/test.xml' |tac |sed -n '/<building>/{s/<.[^>]*>//g;p;q}'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.