Counter program for validation of XML, from Apache --extended to take a schema spec as argument: -s -v -schema foo.xsd Referenced in Harold, XML Bible 1.1, Chap. 20 (From the samples directory of the Xerces parser distribution available at xml.apache.org.) I've edited this version of Counter.java to use the default SAX parser in J2SE, so we don't need any special classpath to run it. Counter.java is in the sax subdirectory of this directory, as is normal because it is in package "sax". To run it, be connected to this directory and do the commands like the examples below. Note the extra output over what is reported in Harold. These are just nitpicking warnings about missing features of the parser, which we don't need to worry about. NEW: These are now removed. This is an example of a tool built using the functionality of the now-standard Java libraries for XML. Examples of use, from Harold's XML Bible, redone with this program: Flags in use: none: just check well-formedness -v: do validation using DTD if there -v -s: do schema validation -v -s -schema foo.xsd use this schema: NEW FEATURE java sax.Counter -v -s valid_greeting.xml outputs: valid_greeting.xml: 344 ms (1 elems, 1 attrs, 0 spaces, 12 chars) java sax.Counter -v -s invalid_greeting.xml [Error] invalid_greeting.xml:6:12: cvc-type.3.1.2: Element 'GREETING' is a simple type, so it must have no element information item [children]. invalid_greeting.xml: 516 ms (2 elems, 1 attrs, 0 spaces, 14 chars) Recursive XML example book.dtd: DTD book.xsd: no-namespace schema book1.xsd: schema with target NS = "book" NEW Note use of elementFormDefault="qualified" in book1.xsd book.xml: plain XML book1.xml: no NS, linkage in doc to DTD book.dtd book2.xml: no NS, linkage in doc to book.xsd book3.xml: default NS, no schema linkage (but valid by book1.xsd) NEW book4.xml: prefix b: for NS, no schema linkage (but valid by book1.xsd) NEW book5.xml: default NS, linkage in doc to book1.xsd NEW book6.xml: prefix b: for NS, schema linkage in doc to book1.xsd NEW Example: use book1.xsd to validate book3.xml java sax/Counter -v -s -schema book1.xsd book3.xml For other examples with book*, see targets in build.xml booktype.xmd: defines BookType, the type of a book in book.xml books.xsd: uses BookType from booktype by import, to set up bookgroup type books.xml: a bookgroup document booksmsg.xml: SOAP message with books xml as body soapbooksmsg.xmd: a schema to validate booksmsg.xml Other older examples: order.dtd: DTD for Order from text order.xsd: schema for Order from text clocks.xml: plain XML clocks1.xml: same XML with DOCTYPE for DTD clocks2.xml: same XML with schema java sax.Counter -v clocks1.xml does DTD validation