• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Jj Roberts
  • Carey Brown
Bartenders:
  • salvin francis
  • Frits Walraven
  • Piet Souris

Xerces: Using the method sax.Counter in xercesSamples.jar from the command line

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

The closest I get is:

java -classpath /xerces-2_9_0/xercesSamples.jar:/xerces-2_9_0/xercesImpl.jar sax.Counter -v -s my_xml_data_file.xml

But where do I specify the name of the xsd file?
 
Ranch Hand
Posts: 732
7
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:
http://www.w3.org/TR/2004/REC-xmlschema-1-20041028/structures.html#xsi_schemaLocation

To help you get the concret idea of it, this is how it operates.
[1] 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.

[2] 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.
 
The moth suit and wings road is much more exciting than taxes. Or this tiny ad:
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic