validate xml with scgema using sax gets a: "Valid documents must have a <!DOCTYPE declaration."

From: Ray Tayek (rtayek.no_at_spam.comcast.net)
Date: 11/30/03


Date: Sun, 30 Nov 2003 06:01:10 GMT

hi, fooling around with xmlspy (which seems pretty broken when *doing*
xslt's). trying to validate in java (1.4) using code from
http://cermics.enpc.fr/doc/java/j2eetutorial-1.4/doc/JAXPSAX13.html
(click on the Echo10.java link). i get an error saying that a doctype
decl is required (see below). i get the same error whether or not i turn
on name space awareness. spy says this file is well formed and valid.
and my java code that transforms it with the same .xslt works as
expected (all the files are at http://tayek.com/~ray/spy1/). the spy
starts the xml doc that i am trying to validate with:

<?xml version="1.0" encoding="UTF-8"?>
<!--Sample XML file generated by XMLSPY v2004 rel. 3
(http://www.xmlspy.com)-->
<inputDocument xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="H:\java\projects\spy1\spy\inputDocument.xsd">
     <special>Text</special>
     <header>
         <inputFieldName>String</inputFieldName>

while the .xsd file starts with:

<?xml version="1.0" encoding="UTF-8"?>
<!-- edited with XMLSPY v2004 rel. 3 U (http://www.xmlspy.com) by Ray
Tayek (Freightgate) -->
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified" attributeFormDefault="unqualified">
     <xs:element name="inputDocument">
         <xs:annotation>
             <xs:documentation>input csv converted to xml</xs:documentation>
         </xs:annotation>

what i would like to do is to validate the xml doc against it's schema
before applying the transform (in java) . i have not yet tried the dom
example at
http://cermics.enpc.fr/doc/java/j2eetutorial-1.4/doc/JAXPDOM9.html as i
thought the sax would be a bit more lightweight.

i just started using spy (i had java code that does the transform just
fine). but i used spy to generate the new .xsd and sample xml. so maybe
he put some proprietary junk in there or something?

anaict, doctype is for dtd's, but sax is complaining about a missing
doctype.

anybody got a clue?

thanks

output from Echo10.java when trying to validate the xml doc:

LOCATOR
  SYS ID: file:H:/java/projects/spy1/spy/inputDocument.xml
START DOCUMENT
<?xml version='1.0' encoding='UTF-8'?>** Warning, line 4, uri
file:H:/java/projects/spy1/spy/inputDocument.xml
    Valid documents must have a <!DOCTYPE declaration.
** Parsing error, line 4, uri
file:H:/java/projects/spy1/spy/inputDocument.xml
    Element type "inputDocument" is not declared.
org.xml.sax.SAXParseException: Element type "inputDocument" is not declared.
         at org.apache.crimson.parser.Parser2.error(Parser2.java:3160)
         at
org.apache.crimson.parser.Parser2.maybeElement(Parser2.java:1322)
         at
org.apache.crimson.parser.Parser2.parseInternal(Parser2.java:500)
         at org.apache.crimson.parser.Parser2.parse(Parser2.java:305)
         at
org.apache.crimson.parser.XMLReaderImpl.parse(XMLReaderImpl.java:442)
         at javax.xml.parsers.SAXParser.parse(SAXParser.java:345)
         at javax.xml.parsers.SAXParser.parse(SAXParser.java:281)
         at V.main(V.java:31)



Relevant Pages

  • Re: Frame java
    ... fragments of a dubious FAQ claiming that every Java application has ... validate(): Widgets have different ... You do not really need to call validateif you just want to display ... Sun's Swing Quick-Start Tutorial: ...
    (comp.lang.java.gui)
  • Java validation using XML schemas
    ... I'm trying to validate a Java object using an XML schema. ... Ideally, I'm looking for an open source solution, but ...
    (comp.lang.java.help)
  • Java validation using XML schemas
    ... I'm trying to validate a Java object using an XML schema. ... Ideally, I'm looking for an open source solution, but ...
    (comp.lang.java.softwaretools)
  • Designing an XML Input Doc for Application
    ... Assume an app has a set of input rules in an xml doc named rules.xml. ... user generates another xml doc (or fragment) named data.xml. ... some ways I can validate data.xml with rules.xml without relying on a ... external script to do the validation. ...
    (comp.text.xml)
  • dinamic variables - help!!!!
    ... functions in java? ... (in perl it's possible!) ... "x", but validate the result as another variable, and return "small ... because i can use that concept to execute ...
    (comp.lang.java.programmer)