5

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:

core-a
core-b
...

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?

Travis Well
  • 183
  • 1
  • 2
  • 8

1 Answers1

4

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
vinc17
  • 11,912
  • 38
  • 45