1

I use xmllint as an external command in VIM editor. When I ran the command below on a buffer containing well-formed xml

%!xmllint --xpath '//a/@href' --encode UTF-8 -

it returned the number of matches that I expected. But as I wanted only the values of href's I ran the other command that made use of string():

%!xmllint --xpath 'string(//a/@href)' --encode UTF-8 -

but I was very surprised to see only the value of the first matched href. Don't I understand something in XPath or is it a bug?

I can attach the source XML (ca 450 lines) if needed but I think it should be clear from the description that the culprit is somewhere else.

ka3ak
  • 2,435
  • 2
  • 30
  • 57
  • First duplicate link explains the behavior you're seeing. (xmllint supports XPath 1.0.) Second duplicate link provides some apropos xmllint tips. – kjhughes Mar 31 '19 at 21:44
  • 1
    @kjhughes Thank you for providing links to the similar questions. So the problem is in the old XPath version that xmllint uses. If xmllint used XPath 2.0 the expression '//a/@href/string()' would do that I expect. Anyway, to workaround the issue I use the first expression '//a/@href' and pipe the result to 'sed' where I only extract the value of href. – ka3ak Apr 01 '19 at 09:00

0 Answers0