Skip to content
Advertisement

Extract section of xml from result of curl command on Linux

I am issuing the following command:

curl http://localhost:8082/some-url

Which returns xml that looks similar to this:

<?xml version="1.0" encoding="UTF-8"?><user><dateCreated>1</dateCreated><dateLastModified>1</dateLastModified><id>1</id><disabled>false</disabled><firstName></firstName><lastName></lastName></user>

What is the easiest way to extract an xml element from the response, e.g. the element “true”?

Note, I want the complete opening tag, content, and closing tag (and the content may also be empty.

Thanks

Advertisement

Answer

Would xmllint be an option for you as well?

$ curl -s http://localhost:8082/some-url | xmllint --xpath '//user/disabled' -
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement