I'm trying to use xmllint to parse names of Solr cores from the configuration file. This works:

xmllint --xpath /solr/cores/core/@name solr.xml |grep -Po '(?<=name=")[a-z-]+(?=")'

And it returns something like:


Which is exactly what I want, but I would like to eliminate grep. It seems like one should be able to do this with just xpath. Without grep, the output looks like:

name="core-a" name="core-b" ...

Wrapping the expressions in string() reduces the multiple output to just the first (ie core-a and that's it), which is not useful. How can I apply the string function on each result?


AFAIK, xmllint is rather limited. But you can use xmlstarlet with its sel command for what you want to do. See xmlstarlet sel --help for usage and an example. With your example, it would be:

xmlstarlet sel -T -t -m /solr/cores/core/@name -v . -n solr.xml

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.