CS639 Notes on project pa1b building and testing

 

In the pa1a solution: “ant test2” runs DumpClass on SortEx:

More specifically, cs639.presentation.DumpClass on examples.sort.SortEx

 

Both class areas are on the classpath, so Java has access to both.

 

The .class files as seen from the base dir:  

      build/classes/cs639/presentation/DumpClass.class

      input/classes/examples/sort/SortEx.class

 

From command line: set the classpath and use it:

 

  java -cp build\classes;input\classes cs639.presentation.DumpClass examples.sort.SortEx

 

In pa1b, DumpClass is replaced by JavaToXML. Output the resulting XML to standard output or file SortEx.xml in base directory. The second option is better for the validation feature.

 

Schemas needed for pa1b: similar to book.xml’s DTD and schema. JavaSource.dtd and javaSource.xsd.

 

Validation feature for JavaToXML:  add flag “-v” to above args:

 

java -cp build\classes;input\classes cs639.presentation.JavaToXML -v examples.sort.SortEx

 

This should validate against JavaSource.dtd, itself in base dir.

Counter.java is now cs639.validation.Counter: just change its package.

 

Of course we can use a new ant target to do the above execution, as required by the delivery instructions. Here is the needed addition for target test3v:

 

      <target name="test3v" depends="build">

          <echo message="JavaToXML for Grid and validate with DTD:"/>

            <java fork="yes" classname="cs639.presentation.JavaToXML" failonerror="true" dir="${basedir}">

                  <classpath refid="execution.classpath" />

                  <arg value="Grid" />

                  <arg value="-v" />   ß second arg to program

            </java>

      </target>

 

 

We know we can use Counter as a program:

java sax.Counter –v Grid.xml      assuming Grid.xml has DOCTYPE (make this happen)

This means calling Counter’s main with String[] containing “-v” and “Grid.xml”

This works if output Grid.xml is in base dir, with DOCTYPE.

 

Debugging XML and schemas

 

First check that your XML Schema and your .xml files are well-formed XML (use a browser or eclipse)

 

Next check Grid.xml, say, vs. JavaSource.xsd.  For this, you can use the convenient –schema flag to Counter:

 

java sax.Counter -s -v -schema JavaSource.xsd Grid.xml

This will accept a "plain" XML file Grid.xml, or one with a DOCTYPE, and validate it using JavaSource.xsd.

 

If you get an error, note the numbers, say 8:14 at the beginning.  That means line 8, column 14 is the place in the XML that the error occurred. Also read the error message of course.

 

Find certain line number: use eclipse Navigate>Go to Line…

 

You can even test your schema against the schema of schemas:

 

java sax.Counter –v –s –schema http://www.w3.org/2001/XMLSchema.xsd JavaSource.xsd


This would help locate misspelled schema element names, for example.

 

DTD validation: you need a DOCTYPE in your .xml file for this.  Then use

 

java sax.Counter –v Grid.xml

 

Since schema validation by Counter works with a DOCTYPE, here is a way to streamline the validation in pa1b:


Thus if you standardize on writing your .xml files with a DOCTYPE but no linkage to .xsd internally, you can use Counter two ways on that file to check validation:

java sax.Counter -v Grid.xml for DTD validation (DOCTYPE says the dtd to use)
java sax.Counter -s -v -schema JavaSource.xsd Grid.xml
  for XML Schema validation

http://cheetah.cs.umb.edu/forums/images/misc/progress.gif

Note that the assignment is to use Counter as a Java class, not as a separate program.  Just set up an array of strings and call main. You shouldn’t need to edit Counter.java.  Just change its package as specified.