Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

xmllint xpath don't print error on empty set

Tags:

bash

xmllint

I'm using xmllint in a bash script to perform an xpath on some data. The xpath will not always match against the data, and this is ok. From xmllint documentation:

--xpath "XPath_expression"
       Run an XPath expression given as argument and print the result. In case of a nodeset result, each node in the node set is serialized in full in the output. In case of an empty node set the "XPath set is
       empty" result will be shown and an error exit code will be returned.

Is there anyway to disable/hide the output XPath set is empty when xmllint doesn't find any matches?

like image 826
Josh Avatar asked Mar 19 '23 13:03

Josh


1 Answers

The message goes to the standard error device. You can redirect it to /dev/null.

Example:

# Shows the message
xmllint --xpath '//a' <(echo "<data/>")

# Redirects the message. Message disappears
xmllint --xpath '//a' <(echo "<data/>") 2>/dev/null
like image 180
hek2mgl Avatar answered Mar 28 '23 11:03

hek2mgl