Skip to content
This repository was archived by the owner on Jan 26, 2026. It is now read-only.

Commit 387a952

Browse files
committed
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.
1 parent e189e99 commit 387a952

2 files changed

Lines changed: 23 additions & 12 deletions

File tree

doc/xmllint.xml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,9 @@
575575
result. In case of a nodeset result, each node in the
576576
node set is serialized in full in the output. In case
577577
of an empty node set the "XPath set is empty" result
578-
will be shown and an error exit code will be returned.
578+
will be shown and exit code 11 will be returned..
579+
This feature is EXPERIMENTAL. Implementation details can
580+
change without futher notice.
579581
</para>
580582
</listitem>
581583
</varlistentry>
@@ -945,6 +947,13 @@
945947
</listitem>
946948
</varlistentry>
947949

950+
<varlistentry>
951+
<term><errorcode>11</errorcode></term>
952+
<listitem>
953+
<para>XPath result is empty</para>
954+
</listitem>
955+
</varlistentry>
956+
948957
</variablelist>
949958
</refsect1>
950959

xmllint.c

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -86,17 +86,18 @@
8686
#endif
8787

8888
typedef enum {
89-
XMLLINT_RETURN_OK = 0, /* No error */
90-
XMLLINT_ERR_UNCLASS = 1, /* Unclassified */
91-
XMLLINT_ERR_DTD = 2, /* Error in DTD */
92-
XMLLINT_ERR_VALID = 3, /* Validation error */
93-
XMLLINT_ERR_RDFILE = 4, /* CtxtReadFile error */
94-
XMLLINT_ERR_SCHEMACOMP = 5, /* Schema compilation */
95-
XMLLINT_ERR_OUT = 6, /* Error writing output */
96-
XMLLINT_ERR_SCHEMAPAT = 7, /* Error in schema pattern */
97-
XMLLINT_ERR_RDREGIS = 8, /* Error in Reader registration */
98-
XMLLINT_ERR_MEM = 9, /* Out of memory error */
99-
XMLLINT_ERR_XPATH = 10 /* XPath evaluation error */
89+
XMLLINT_RETURN_OK = 0, /* No error */
90+
XMLLINT_ERR_UNCLASS = 1, /* Unclassified */
91+
XMLLINT_ERR_DTD = 2, /* Error in DTD */
92+
XMLLINT_ERR_VALID = 3, /* Validation error */
93+
XMLLINT_ERR_RDFILE = 4, /* CtxtReadFile error */
94+
XMLLINT_ERR_SCHEMACOMP = 5, /* Schema compilation */
95+
XMLLINT_ERR_OUT = 6, /* Error writing output */
96+
XMLLINT_ERR_SCHEMAPAT = 7, /* Error in schema pattern */
97+
XMLLINT_ERR_RDREGIS = 8, /* Error in Reader registration */
98+
XMLLINT_ERR_MEM = 9, /* Out of memory error */
99+
XMLLINT_ERR_XPATH = 10, /* XPath evaluation error */
100+
XMLLINT_ERR_XPATH_EMPTY = 11 /* XPath result is empty */
100101
} xmllintReturnCode;
101102
#ifdef LIBXML_DEBUG_ENABLED
102103
static int shell = 0;
@@ -2019,6 +2020,7 @@ static void doXPathDump(xmlXPathObjectPtr cur) {
20192020
xmlOutputBufferPtr buf;
20202021

20212022
if ((cur->nodesetval == NULL) || (cur->nodesetval->nodeNr <= 0)) {
2023+
progresult = XMLLINT_ERR_XPATH_EMPTY;
20222024
if (!quiet) {
20232025
fprintf(stderr, "XPath set is empty\n");
20242026
}

0 commit comments

Comments
 (0)