Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > validate xml with scgema using sax gets a: "Valid documents musthave a <!DOCTYPE declaration."

Reply
Thread Tools

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

 
 
Ray Tayek
Guest
Posts: n/a
 
      11-30-2003
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/j2ee...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 xmlnssi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="H:\java\projects\sp y1\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 xmlnss="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/j2ee.../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.ja va:3160)
at
org.apache.crimson.parser.Parser2.maybeElement(Par ser2.java:1322)
at
org.apache.crimson.parser.Parser2.parseInternal(Pa rser2.java:500)
at org.apache.crimson.parser.Parser2.parse(Parser2.ja va:305)
at
org.apache.crimson.parser.XMLReaderImpl.parse(XMLR eaderImpl.java:442)
at javax.xml.parsers.SAXParser.parse(SAXParser.java:3 45)
at javax.xml.parsers.SAXParser.parse(SAXParser.java:2 81)
at V.main(V.java:31)
 
Reply With Quote
 
 
 
 
Andrew Thompson
Guest
Posts: n/a
 
      11-30-2003
"Ray Tayek" <(E-Mail Removed)> wrote in message
news:GIfyb.360196$HS4.3010339@attbi_s01...
> 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/j2ee...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


Did you lose your shift key, Ray?
....
> Valid documents must have a <!DOCTYPE declaration.


Try this as your 1st line..
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

And for reference, an URL would be _so_ much easier.

--
Andrew Thompson
* http://www.PhySci.org/ PhySci software suite
* http://www.1point1C.org/ 1.1C - Superluminal!
* http://www.AThompson.info/andrew/ personal site


 
Reply With Quote
 
 
 
 
Ray Tayek
Guest
Posts: n/a
 
      11-30-2003
Andrew Thompson wrote:

> "Ray Tayek" <(E-Mail Removed)> wrote in message
> news:GIfyb.360196$HS4.3010339@attbi_s01...
>
>>
>>... trying to validate in java (1.4) using code from
>>http://cermics.enpc.fr/doc/java/j2ee...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

>
>
> Did you lose your shift key, Ray?
> ...


no, it's just a *very* old habbit.
>
>> Valid documents must have a <!DOCTYPE declaration.

>
>
> Try this as your 1st line..
> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
>


spy says these are still valid and this works fine and i just get a few
warnigs:

...Declared encoding "UTF-8" does not match actual one "Cp1252"; this
might not be an error.
Using original entity definition for "&quot;".
Using original entity definition for "&amp;".
Using original entity definition for "&lt;".
Using original entity definition for "&gt;".
Using original entity definition for "&apos;".
Time: 6.21

now i can try to write the xslt that will write that xslt

but i really do want to produce xml, not html or xhtml (i think) as this
will be processed only by an xslt.

> And for reference, an URL would be _so_ much easier.


i assume you mean:
xsi:noNamespaceSchemaLocation="H:\java\projects\sp y1\spy\inputDocument.xsd"?

if so, i agree as spy complains whem i move stuff around. what would the
url for that look like?

thanks for your assistance!
---
ray tayek http://tayek.com/ actively seeking mentoring or telecommuting work
vice chair orange county java users group http://www.ocjug.org/
hate spam? http://samspade.org/ssw/
 
Reply With Quote
 
Ray Tayek
Guest
Posts: n/a
 
      11-30-2003
Andrew Thompson wrote:
....
> > Try this as your 1st line..

> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
>


is there something similar for my .xsd's? it would be nice to do some
validation on them?

thanks
---
ray tayek http://tayek.com/ actively seeking mentoring or telecommuting work
vice chair orange county java users group http://www.ocjug.org/
hate spam? http://samspade.org/ssw/
 
Reply With Quote
 
Andrew Thompson
Guest
Posts: n/a
 
      11-30-2003
"Ray Tayek" <(E-Mail Removed)> wrote in message
news:0_gyb.366660$Fm2.366085@attbi_s04...
> Andrew Thompson wrote:

....
> > Did you lose your shift key, Ray?
> > ...

>
> no, it's just a *very* old habbit.


Hobbits are very old, whereas habits are just ingrained.

> >> Valid documents must have a <!DOCTYPE declaration.

> >
> >
> > Try this as your 1st line..
> > <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
> > "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
> >

>
> spy says these are still valid and this works fine and i just get a few
> warnigs:

....
> but i really do want to produce xml, not html or xhtml (i think) as this
> will be processed only by an xslt.


(shrugs vaguely) I was really just guessing anyway.

The only thing I knew was that valid web pages
have a DOCTYPE, I chose that one at random,
from the list the validator supplies in it's report
page, vis.
http://validator.w3.org/check?uri=ht...g%2F&charset=%
28detect+automatically%29&doctype=%28detect+automa tically%29

> > And for reference, an URL would be _so_ much easier.

>
> i assume you mean:
>

xsi:noNamespaceSchemaLocation="H:\java\projects\sp y1\spy\inputDocument.xsd"?

No! I meant an URL on the net where we could
see your page break. It is much easier than transcribing
errors to Usenet posts.

In an ideal world you would put a regular index.html
file that links to the URL in question, the source files etc.

--
Andrew Thompson
* http://www.PhySci.org/ PhySci software suite
* http://www.1point1C.org/ 1.1C - Superluminal!
* http://www.AThompson.info/andrew/ personal site


 
Reply With Quote
 
Ray Tayek
Guest
Posts: n/a
 
      11-30-2003
Andrew Thompson wrote:
> "Ray Tayek" <(E-Mail Removed)> wrote in message
> news:0_gyb.366660$Fm2.366085@attbi_s04...
>
>>Andrew Thompson wrote:

>

....
>
>>but i really do want to produce xml, not html or xhtml (i think) as this
>> will be processed only by an xslt.

>
>
> (shrugs vaguely) I was really just guessing anyway.


i found a list at: http://www.w3.org/QA/2002/04/valid-dtd-list.html#full
- yours seems to be the best fit.
>
> ...
> http://validator.w3.org/check?uri=ht...g%2F&charset=%
> 28detect+automatically%29&doctype=%28detect+automa tically%29
>


nice site, thanks for the link
>
>>>And for reference, an URL would be _so_ much easier.

>>
>>i assume you mean: ...
>>

> No! I meant an URL on the net...


oh, sure, here: http://tayek.com/~ray/spy1/

thanks
---
ray tayek http://tayek.com/ actively seeking mentoring or telecommuting work
vice chair orange county java users group http://www.ocjug.org/
hate spam? http://samspade.org/ssw/
 
Reply With Quote
 
Andrew Thompson
Guest
Posts: n/a
 
      11-30-2003
"Ray Tayek" <(E-Mail Removed)> wrote in message
news:yrhyb.167099$Dw6.655869@attbi_s02...
....
> >..I meant an URL on the net...

>
> oh, sure, here: http://tayek.com/~ray/spy1/


Aha, yep, _that's_ what I'm talking about!

Now hopefully the experts will jump in and answer
the more technical aspects of your question.

--
Andrew Thompson
* http://www.PhySci.org/ PhySci software suite
* http://www.1point1C.org/ 1.1C - Superluminal!
* http://www.AThompson.info/andrew/ personal site


 
Reply With Quote
 
Ray Tayek
Guest
Posts: n/a
 
      11-30-2003
Andrew Thompson wrote:
> "Ray Tayek" <(E-Mail Removed)> wrote in message
> news:yrhyb.167099$Dw6.655869@attbi_s02...
> ...
>
>>>..I meant an URL on the net...

>>
>>oh, sure, here: http://tayek.com/~ray/spy1/

>
>
> Aha, yep, _that's_ what I'm talking about!
>
> Now hopefully the experts will jump in and answer
> the more technical aspects of your question.
>


that would be cool.

unfortunately, i lied. the "success" that i quoted last time was because
i was running the wrong program. i needed to run the validator (not the
testCase). so it still thinks the inputDocument is not defined. there is
no mention of the .xsd, so maybe it's a typo somewhere (sigh). i will
put the validation calls in the test case so i don't forget them again.

thanks.

LOCATOR
SYS ID: file:H:/java/projects/spy1/spy/inputDocument.xml
START DOCUMENT
<?xml version='1.0' encoding='UTF-8'?>** Warning, line 25, uri
http://www.w3.org/TR/xhtml1/DTD/xhtml-special.ent
Using original entity definition for "&quot;".
** Warning, line 26, uri http://www.w3.org/TR/xhtml1/DTD/xhtml-special.ent
Using original entity definition for "&amp;".
** Warning, line 27, uri http://www.w3.org/TR/xhtml1/DTD/xhtml-special.ent
Using original entity definition for "&lt;".
** Warning, line 28, uri http://www.w3.org/TR/xhtml1/DTD/xhtml-special.ent
Using original entity definition for "&gt;".
** Warninorg.xml.sax.SAXParseException: Element type "inputDocument" is
not declared.
at org.apache.crimson.parser.Parser2.error(Parser2.ja va:3160)
at
org.apache.crimson.parser.Parser2.maybeElement(Par ser2.java:1322)
at org.apache.crimson.parser.Parser2.parseg, line 29, uri
http://www.w3.org/TR/xhtml1/DTD/xhtml-special.ent
Using original entity definition for "&apos;".
** Parsing error, line 5, uri
file:H:/java/projects/spy1/spy/inputDocument.xml
Element type "inputDocument" is not declared.
Internal(Parser2.java:500)
at org.apache.crimson.parser.Parser2.parse(Parser2.ja va:305)
at
org.apache.crimson.parser.XMLReaderImpl.parse(XMLR eaderImpl.java:442)
at javax.xml.parsers.SAXParser.parse(SAXParser.java:3 45)
at javax.xml.parsers.SAXParser.parse(SAXParser.java:2 81)
at V.main(V.java:31)



--
---
ray tayek http://tayek.com/ actively seeking mentoring or telecommuting work
vice chair orange county java users group http://www.ocjug.org/
hate spam? http://samspade.org/ssw/
 
Reply With Quote
 
Chris Smith
Guest
Posts: n/a
 
      11-30-2003
Ray,

First of all, the suggestion to specify an HTML doctype was not a
particularly good one (sorry, Andrew!). Not only is your document not
HTML at all (and thus you're lying to the parser), but the HTML DTDs
specified are SGML DTDs anyway, hence the warnings you're getting when
trying to use them! You want to remove the DTD declaration, and then
fix the problem that's causing the parser to expect a DTD declaration.

Furthermore, the equally important (if not as obvious) issue is that the
validator is probably not validating against the XML schema anyway!
Again, you need to fix the real problem.

The real problem appears to be (just a guess here, since I don't have
much information) that you're using a SAX parser that doesn't know about
XML schema, and/or that you're not configuring it properly to use schema
anyway. You didn't read that web page you pointed out very well,
because you grabbed the code which simply sets the parser to
"validating" from the very beginning of the page, and you didn't do ANY
of the things that are mentioned later in the page, about setting the
parser to be namespace-aware (which mystically appears in your code, but
as the predicate of an "if (false)" statement), setting the
schemaLanguage property, and so forth.

I'd suggest you follow the instructions from the page of the Java
Tutorial first, and if that doesn't work, look into the possibility that
you have a parser configured that's not schema-aware at all. It is
possible to change the parser that's used by JAXP.

--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 
Reply With Quote
 
Ray Tayek
Guest
Posts: n/a
 
      12-01-2003
Chris Smith wrote:
>... Not only is your document not HTML at all ...
> ... You want to remove the DTD declaration, and then
> fix the problem that's causing the parser to expect a DTD declaration.
>

ok

> Furthermore, the equally important (if not as obvious) issue is that the
> validator is probably not validating against the XML schema anyway!
> Again, you need to fix the real problem.
>
> The real problem appears to be (just a guess here, since I don't have
> much information) that you're using a SAX parser that doesn't know about
> XML schema, and/or that you're not configuring it properly to use schema
> anyway.


i will check this.

You didn't read that web page you pointed out very well,
> because you grabbed the code which simply sets the parser to
> "validating" from the very beginning of the page, and you didn't do ANY
> of the things that are mentioned later in the page, about setting the
> parser to be namespace-aware (which mystically appears in your code, but
> as the predicate of an "if (false)" statement), setting the
> schemaLanguage property, and so forth.


was trying it both ways to see if it made any difference. i grabbed
echo10 ans sorta assumed it woud do the right thing. it is not. and
doing a: saxParser.setProperty(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA);
throws a no reconnized (sigh).
>
> I'd suggest you follow the instructions from the page of the Java
> Tutorial first, and if that doesn't work, look into the possibility that
> you have a parser configured that's not schema-aware at all. It is
> possible to change the parser that's used by JAXP.
>


i was just grabbig whatever the factory made.

thanks

---
ray tayek http://tayek.com/ actively seeking mentoring or telecommuting work
vice chair orange county java users group http://www.ocjug.org/
hate spam? http://samspade.org/ssw/
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Different results parsing a XML file with XML::Simple (XML::Sax vs. XML::Parser) Erik Wasser Perl Misc 5 03-05-2006 10:09 PM
Unable to validate XML Schema with SAX Parser: fhuddles Java 1 02-15-2005 02:58 PM
processing XHTML1.1 documents with xml.sax webworldL@yahoo.com Python 1 08-09-2004 05:53 PM
Validate Using SAX in eclipse soni Java 2 12-02-2003 02:16 PM
validate xml with sax? Ray Tayek XML 0 11-30-2003 12:07 AM



Advertisments