Schemas needed for pa1b: similar to book.xml’s DTD and schema. JavaSource.dtd and javaSource.xsd.
Validation feature for JavaToXML: add flag “-v” so running from the command line (Windows case):
java -cp
build\classes;input\classes
cs639.presentation.JavaToXML -v examples.sort.SortEx
^ replace with : for UNIX/Mac/Linux
This should validate against JavaSource.dtd, itself in base dir.
Here Counter.java is now cs639.validation.Counter: just change its package.
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”
So your own program can call Counter’s main with String[] loaded properly.
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>
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
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.