xmllint : how to validate an XML using a local DTD file
First of all, external DTDs do not need the <!DOCTYPE
preamble - remove it from the DTD file:
<!ELEMENT coord (date)><!ELEMENT date (#PCDATA)>
Then, --loaddtd
fetches an external DTD, which is not the same as validating against an external DTD. Use the --dtdvalid
option as follows:
$ xmllint --noout --dtdvalid test.dtd test.xml
If the XML document is valid, xmllint will not output anything (because of --noout
). If you change the DTD to, say:
<!ELEMENT coord (date,other)><!ELEMENT date (#PCDATA)>
The output will be
$ xmllint --noout --dtdvalid test.dtd test.xmltest.xml:2: element coord: validity error : Element coord content does not follow the DTD, expecting (date , other), got (date )Document test.xml does not validate against test.dtd
Look for more information on the doc pages of NMT or XMLSoft.