Re: xmllint: Exit code 0 despite undefined namespace prefix

BR Chrisman via xml <[email protected]> Mon, 21 Jun 2021 00:59:34 -0700
Newsgroups gmane.comp.gnome.lib.xml.general
Message-ID <CAN4=B2nvPD_2Eapc0vzMLFGorbt7Fqaa603wDNHLQCGbKO=u1g@mail.gmail.com>
--===============9031813759057075921==
Content-Type: multipart/alternative; boundary="0000000000007dd28e05c5420e62"

--0000000000007dd28e05c5420e62
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

I wondered about that as well a while back.
The manpage specifies the exit statuses below.  The document is well-formed
and shouldn't fail to parse because the namespace-prefix separating ':' was
always allowed as part of a tag name iirc.
There's no schema, so it's not a schema validation issue.
There's no exit status that would reasonably  be returned, though stderr
says it's a namespace 'error', so "0 No error" also doesn't seem completely
correct.
However, I've seen multiple applications that rely on xmllint *not* exiting
other-than-0 due to missing namespace prefixes.
Could possibly double-pass it with xmllint file 2>&1 > /dev/null | grep
namespace.error


DIAGNOSTICS
       xmllint return codes provide information that can be used when
calling it from scripts.

       0
           No error

       1
           Unclassified

       2
           Error in DTD

       3
           Validation error

       4
           Validation error

       5
           Error in schema compilation

       6
           Error writing output

       7
           Error in pattern (generated when --pattern option is used)

       8
           Error in Reader registration (generated when --chkregister
option is used)

       9
           Out of memory error

On Sun, Jun 20, 2021 at 11:59 PM Christian Weiske via xml <[email protected]>
wrote:

> Hello,
>
>
> I'm using xmllint to validate files automatically during CI runs, and
> now an error was not catched.
>
> The xml file used a namespace prefix that was not defined. xmllint
> noticed that, but still gave an exit code of 0:
>
> > $ xmllint --noout text.xml; echo $?
> > text.xml:66: namespace error : Namespace prefix v on tag is not defined
> >         <v:tag/>
> >               ^
> > 0
>
> Is there a way to make xmllint use a non-0 exit code in this case?
>
> (Happens on Ubuntu Linux 20.04:
> xmllint: using libxml version 20912
>     compiled with: Threads Tree Output Push Reader Patterns Writer SAXv1
> FTP HTTP DTDValid HTML Legacy C14N Catalog XPath XPointer XInclude Iconv
> ICU ISO8859X Unicode Regexps Automata Schemas Schematron Modules Debug
> Zlib Lzma
> )
>
> --
> Regards/Mit freundlichen Gr=C3=BC=C3=9Fen
> Christian Weiske
>
> -=3D=E2=89=A1 Geeking around in the name of science since 1982 =E2=89=A1=
=3D-
> _______________________________________________
> xml mailing list, project page  http://xmlsoft.org/
> [email protected]
> https://mail.gnome.org/mailman/listinfo/xml
>

--0000000000007dd28e05c5420e62
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div>I wondered about that as well a while back.</div>The =
manpage specifies the exit statuses below.=C2=A0 The document is well-forme=
d and shouldn&#39;t fail to parse because the namespace-prefix separating &=
#39;:&#39; was always allowed as part of a tag name iirc.<div>There&#39;s n=
o schema, so it&#39;s not a schema validation issue.</div><div>There&#39;s =
no exit status=C2=A0that would reasonably=C2=A0 be returned, though stderr =
says it&#39;s a namespace &#39;error&#39;, so &quot;0 No error&quot; also d=
oesn&#39;t seem completely correct.</div><div>However, I&#39;ve seen multip=
le applications that rely on xmllint *not*=C2=A0exiting other-than-0 due to=
 missing namespace prefixes.</div><div><div>Could possibly double-pass it w=
ith xmllint file 2&gt;&amp;1 &gt; /dev/null | grep namespace.error</div><di=
v><br></div><div><br><div>DIAGNOSTICS<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0xmllint=
 return codes provide information that can be used when calling it from scr=
ipts.<br><br>=C2=A0 =C2=A0 =C2=A0 =C2=A00<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0No error<br><br>=C2=A0 =C2=A0 =C2=A0 =C2=A01<br>=C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0Unclassified<br><br>=C2=A0 =C2=A0 =C2=A0 =C2=A02=
<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0Error in DTD<br><br>=C2=A0 =C2=
=A0 =C2=A0 =C2=A03<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0Validation e=
rror<br><br>=C2=A0 =C2=A0 =C2=A0 =C2=A04<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0Validation error<br><br>=C2=A0 =C2=A0 =C2=A0 =C2=A05<br>=C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0Error in schema compilation<br><br>=C2=A0=
 =C2=A0 =C2=A0 =C2=A06<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0Error wr=
iting output<br><br>=C2=A0 =C2=A0 =C2=A0 =C2=A07<br>=C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0Error in pattern (generated when --pattern option is us=
ed)<br><br>=C2=A0 =C2=A0 =C2=A0 =C2=A08<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0Error in Reader registration (generated when --chkregister option=
 is used)<br><br>=C2=A0 =C2=A0 =C2=A0 =C2=A09<br>=C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0Out of memory error<br></div></div></div></div><br><div cl=
ass=3D"gmail_quote"><div dir=3D"ltr" class=3D"gmail_attr">On Sun, Jun 20, 2=
021 at 11:59 PM Christian Weiske via xml &lt;<a href=3D"mailto:[email protected]=
g">[email protected]</a>&gt; wrote:<br></div><blockquote class=3D"gmail_quote" =
style=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);pa=
dding-left:1ex">Hello,<br>
<br>
<br>
I&#39;m using xmllint to validate files automatically during CI runs, and <=
br>
now an error was not catched.<br>
<br>
The xml file used a namespace prefix that was not defined. xmllint <br>
noticed that, but still gave an exit code of 0:<br>
<br>
&gt; $ xmllint --noout text.xml; echo $?<br>
&gt; text.xml:66: namespace error : Namespace prefix v on tag is not define=
d<br>
&gt;=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0&lt;v:tag/&gt;<br>
&gt;=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0^<br>
&gt; 0<br>
<br>
Is there a way to make xmllint use a non-0 exit code in this case?<br>
<br>
(Happens on Ubuntu Linux 20.04:<br>
xmllint: using libxml version 20912<br>
=C2=A0 =C2=A0 compiled with: Threads Tree Output Push Reader Patterns Write=
r SAXv1 <br>
FTP HTTP DTDValid HTML Legacy C14N Catalog XPath XPointer XInclude Iconv <b=
r>
ICU ISO8859X Unicode Regexps Automata Schemas Schematron Modules Debug <br>
Zlib Lzma<br>
)<br>
<br>
-- <br>
Regards/Mit freundlichen Gr=C3=BC=C3=9Fen<br>
Christian Weiske<br>
<br>
-=3D=E2=89=A1 Geeking around in the name of science since 1982 =E2=89=A1=3D=
-<br>
_______________________________________________<br>
xml mailing list, project page=C2=A0 <a href=3D"http://xmlsoft.org/" rel=3D=
"noreferrer" target=3D"_blank">http://xmlsoft.org/</a><br>
<a href=3D"mailto:[email protected]" target=3D"_blank">[email protected]</a><br>
<a href=3D"https://mail.gnome.org/mailman/listinfo/xml" rel=3D"noreferrer" =
target=3D"_blank">https://mail.gnome.org/mailman/listinfo/xml</a><br>
</blockquote></div>

--0000000000007dd28e05c5420e62--

--===============9031813759057075921==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
xml mailing list, project page  http://xmlsoft.org/
[email protected]
https://mail.gnome.org/mailman/listinfo/xml

--===============9031813759057075921==--