62

i have to validate my xml file with a given XSD file. Figured the easiest way to do so would be xmllint, but i can't get it to work. Can anyone tell me the exact command?

I tried:

     xmllint --valid myxsd.xsd myxml.xml

What am i doing wrong? This only outputs the 2 files in the command line

edit: have to do it in console, because it will be needed in a build process

Econ
  • 2,419
  • 3
  • 13
  • 18

1 Answers1

162

Figured it out, had to use --schema instead of --validate.

xmllint --schema yourxsd.xsd yourxml.xml --noout

The --noout makes sure your code in XSD and XML doesn't show. With this option you will only see the Validation Errors.

Marecky
  • 1,924
  • 2
  • 25
  • 39
Econ
  • 2,419
  • 3
  • 13
  • 18
  • I tried it and faced this limitation `Internal error: xmlSchemaVDocWalk, there is at least one entity reference in the node-tree currently being validated. Processing of entities with this XML Schema processor is not supported (yet). Please substitute entities before validation.`, so it does not support entities even though they are correctly defined like ` ]>`. – dma_k Apr 28 '20 at 10:13
  • 4
    `apt search xmllint` finds `libxml2-utils`, so `sudo apt install libxml2-utils` – Weekend Sep 24 '20 at 09:09
  • Thanks. I tried the `--dtdvalid` option, that didn't work. – 9-Pin Aug 02 '23 at 01:26