Found the solution. Simply append 2>/dev/null to the command:
2>/dev/null
content=$(xpath ../../AndroidManifest.xml /manifest/@android:versionCode 2>/dev/null)
Output:
android:versionCode="38"
From man xpath:
man xpath
-q Be quiet. Output only errors (and no separator) on stderr.
Better use xpath -q ... instead of piping all stderr-messages. This will make sure actual errors will continue to be printed, but no other status output / node dividers.
xpath -q ...
-q did not work for me. Since xpath utulity prints extra output on std-err, just redirect it to /dev/null
xpath file.xml '/foo/bar/text()' 2>/dev/null