xmllint xpath don't print error on empty set
Asked Answered
T

1

5

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?

Turtleneck answered 22/5, 2014 at 16:51 Comment(1)
Did you confirm that the error message is written to stderr? You can discard all error msgs with xmllint ... 2>/dev/null or merge the outputs (losing the distinction between stdout and stderr) like xlmlint ... 2>&1 | egrep -v 'XPath set is empty|possibly other msgs you don_t care about' Good luck.Interlining
K
9

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
Kenny answered 22/5, 2014 at 19:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.