Command line xmllint --schema validation fails but $? returns 0
myinput.xml:
<myinput><header>mytestvalue</header></myinput>
myschema.xsd
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="myinput" type="xsd:string"/>
</xsd:schema>
Command:
$xmllint --schema myschema.xsd myinput.xml
Result:
Element myinput: child header should not be present
myinput.xml fails to validate
Command:
$echo $?
Result:
0
Could someone tell me why xmllint schema validation failure is not returned as an error? Or suggest me ways to capture this as an error in my shell script? In my shell script, current I am validating the above xmllint command in an "if" block and it fails only for xml well-formedness but succeeds for schema validation failure.
if the above is not returned as error, should I go about doing the ugly way of "grep fails" on the xmllint output to figure-out if schema validation succeeded or failed? Any thoughts?
$?
imediately after thexmllint
line or a few lines of code later?$?
pertains to the return code of the preceding statement, if you've got anecho
in between or something you'll be reading thatecho
's$?
. – Lordosis