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
XML documents are validated by the Create method of the XmlReader class. To validate an XML document, construct an XmlReaderSettings object that contains an XML schema definition language (XSD) schema with which to validate the XML document.
You can validate your XML documents against XML schemas only; validation against DTDs is not supported. However, although you cannot validate against DTDs, you can insert documents that contain a DOCTYPE or that refer to DTDs.
Reference the XSD schema in the XML document using XML schema instance attributes such as either xsi:schemaLocation or xsi:noNamespaceSchemaLocation. Add the XSD schema file to a schema cache and then connect that cache to the DOM document or SAX reader, prior to loading or parsing the XML document.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With