Command-line XML validator for Windows Command-line XML validator for Windows xml xml

Command-line XML validator for Windows


Your first option, xmllint (libxml2), does give line numbers for errors in the xml (and also in the xsd). You probably just need a later version. I just confirmed both using my copy, which is:

>  xmllint --versionxmllint: using libxml version 20627

Example output:

invalidXml.xml:4: element c: Schemas validity error : Element 'c': This element is not expected. Expected is ( b ).invalidXml.xml fails to validate<?xml version="1.0"?><invalidXmlEg>  <a/><!--  <b></b> -->  <c/></invalidXmlEg>

Where the xsd is:

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">  <xs:element name="invalidXmlEg">    <xs:complexType>      <xs:sequence>        <xs:element name="a" type="xs:string" />        <xs:element name="b" type="xs:string" />        <xs:element name="c" type="xs:string" />      </xs:sequence>    </xs:complexType>  </xs:element></xs:schema>

NOTE: I have noticed that xmllint will accept elements names that it shouldn't (e.g. "<invalidXml.xsd>"), but this doesn't seem to affect your task.

EDIT adding the "compiled with" part of the version:

 compiled with: Threads Tree Output Push Reader Patterns Writer SAXv1 FTP HTTP DTDValid HTML Legacy C14N Catalog XPath XPointer XInclude Iconv ISO8859X Unicode Regexps Automata Expr Schemas Schematron Modules Debug Zlib 


As 13ren stated above, libxml's xmllint does report line numbers - perhaps you have a version issue. You might find it useful to grab native (non cygwin) versions of the libxml/libxslt tools from http://www.zlatkovic.com/libxml.en.html

You might also want to take a look at msv from Sun. It isn't a full implementation of XSD but might do the job (I use it for RelaxNG validation generally)


I would suggest Windows Powershell with PowerShell Community eXtensions. PSCX has the Test-Xml cmdlet which has the following Get-Help detailed description:

Tests for well formedness and optionally validates against XML Schema. It doesn't handle specifying the targetName space. To see validation error messages, specify the -Verbose flag.

I do not know if it reports the errors with linenumbers but 3 out 4 isn't bad.