Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to Validate a XML file with XSD through xmllint [duplicate]

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

like image 738
Econ Avatar asked Mar 15 '17 11:03

Econ


People also ask

How do I validate an XML file?

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.

Can we validate XML documents against so schema?

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.

How do I reference an XSD file in XML?

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.


1 Answers

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.

like image 85
Econ Avatar answered Oct 13 '22 18:10

Econ