I am looking for a way to validate XML from the command line. I have an XML file and an XSD file (an XML Schema definition file). My objective is to make sure the XML file follows the rules defined in the XSD file.
I noticed that Xerces has a xercesSamples.jar file that comes with a sax.Counter method. My understanding is that this method will count, and also do validation if you use the -v switch. But I can't figure out how to call it from the command line and provide the XML file name and the XSD file name.
If you want to use the sample/demo application sax.Counter class (not a "method" properly speaking) as a vehicle of validating an xml document, just note that it is not its principal functionality. Hence, it could appear fairly restrictive in that regard, meaning the information of schema location has to be provisioned inside the xml document via the XMLSchema-instance (xsi) namespace's vocabulary, namely the attribute added to the root of the xml document: xsi:schemaLocation (if it is defined in a non-null namespace) or xsi:noNamespaceSchemaLocation. Here is the reference, tracing the links further for syntax and specific detail of it:
To help you get the concret idea of it, this is how it operates.
 Suppose your xml document's root is "root" defined in a namespace "urn:xyz" with prefix "pfx" say, and the schema document abc.xsd is in the same directory of the xml, the root should appear something like this.
 Suppose the same root but it has no namespace attached to to it, the root would appear something like this.
Then you can switch on -v and watch for the validation error messages in std.err.
subject: Xerces: Using the method sax.Counter in xercesSamples.jar from the command line