1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2024-12-25 23:21:26 +03:00

xmllint: Return error code if XPath returns empty nodeset

Return an error code as before but make it possible to distinguish from
real errors.

Fixes #690.
This commit is contained in:
Nick Wellnhofer 2024-02-12 16:45:16 +01:00
parent a9e73f11c0
commit 87bebd25f1
2 changed files with 21 additions and 12 deletions

View File

@ -575,7 +575,7 @@
result. In case of a nodeset result, each node in the result. In case of a nodeset result, each node in the
node set is serialized in full in the output. In case node set is serialized in full in the output. In case
of an empty node set the "XPath set is empty" result of an empty node set the "XPath set is empty" result
will be shown unless the <option>--quiet</option> is set. will be shown and exit code 11 will be returned..
This feature is EXPERIMENTAL. Implementation details can This feature is EXPERIMENTAL. Implementation details can
change without futher notice. change without futher notice.
</para> </para>
@ -947,6 +947,13 @@
</listitem> </listitem>
</varlistentry> </varlistentry>
<varlistentry>
<term><errorcode>11</errorcode></term>
<listitem>
<para>XPath result is empty</para>
</listitem>
</varlistentry>
</variablelist> </variablelist>
</refsect1> </refsect1>

View File

@ -100,7 +100,8 @@ typedef enum {
XMLLINT_ERR_SCHEMAPAT = 7, /* Error in schema pattern */ XMLLINT_ERR_SCHEMAPAT = 7, /* Error in schema pattern */
XMLLINT_ERR_RDREGIS = 8, /* Error in Reader registration */ XMLLINT_ERR_RDREGIS = 8, /* Error in Reader registration */
XMLLINT_ERR_MEM = 9, /* Out of memory error */ XMLLINT_ERR_MEM = 9, /* Out of memory error */
XMLLINT_ERR_XPATH = 10 /* XPath evaluation error */ XMLLINT_ERR_XPATH = 10, /* XPath evaluation error */
XMLLINT_ERR_XPATH_EMPTY = 11 /* XPath result is empty */
} xmllintReturnCode; } xmllintReturnCode;
#ifdef LIBXML_DEBUG_ENABLED #ifdef LIBXML_DEBUG_ENABLED
static int shell = 0; static int shell = 0;
@ -2031,6 +2032,7 @@ static void doXPathDump(xmlXPathObjectPtr cur) {
int i; int i;
if ((cur->nodesetval == NULL) || (cur->nodesetval->nodeNr <= 0)) { if ((cur->nodesetval == NULL) || (cur->nodesetval->nodeNr <= 0)) {
progresult = XMLLINT_ERR_XPATH_EMPTY;
if (!quiet) { if (!quiet) {
fprintf(stderr, "XPath set is empty\n"); fprintf(stderr, "XPath set is empty\n");
} }