Re: Validate XML against DTD? XSD OK. SSCCE.
Andrew Thompson wrote:
Piotr Kobzda wrote:
Does anybody demonstrate how to validate against DTD?
..
You may also do something I call validation of a rewritten XML against a
given DTD, an example is there:
<http://groups.google.pl/group/comp.lang.java.programmer/msg/ce4940523b837d20?>
I had meant to revisit that. Unfortunately I get along the lines of..
D:\java ValidateJNLP
org.xml.sax.SAXParseException: White space is required after
the element type "update" in the element type declaration.
Exception in thread "main" org.xml.sax.SAXParseException:
White space is required after the element type "update" in
the element type declaration.
at com.sun.org.apache.xerces.internal.parsers.
AbstractSAXParser.parse(AbstractSAXParser.java:1231)
..
My guess is you are probably using invalid DTD with it. Have you
applied mandatory corrections to DTD?
How about I/we rework it to a form that can pull the XML/DTD
directly off the net, and upload it to the same directory on
my site? Perhaps that is the better example to continue with.
See no problem with that.
In addition, you/we have to change the following lines of the example:
XMLEvent e = er.nextEvent();
if (e.isStartElement()) {
// creatre new DTD
DTD dtd = xef.createDTD("<!DOCTYPE jnlp"
+ " SYSTEM \"" + dtd_file.toURI() + "\">");
That implements requirement of JNLP specification for rooting the
document with 'jnlp' element. However, general purpose validator should
rather rewrite a DTD as follows:
DTD dtd = xef.createDTD("<!DOCTYPE "
+ e.asStartElement().getName().getLocalPart()
+ " SYSTEM \"" + dtd_file.toURI() + "\">");
The example requires also to take into consideration at least: 1) XML
namespaces (I never tried that with StAX); 2) rewriting full document is
not necessary, only the DTD part needs to be rewritten, after that the
processing may be streamed; 3) URIs should be resolved a way causing
reading DTD from stream rather than file; ...
P.S.
I e-mailed you twice today, but I'm not sure you received my message...
Anyway, if you think I can help you with extending that somehow, you
are welcome to e-mail me.
My alternative e-mail: pikob (at) op (dot) pl.
piotr