• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Why isn't the parser validating an xml against a schema

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Guys, as the subject suggests, i have turned on validation via:

The reason I've set dynamic to true is because if an xml file does not include a schema to validate against, then I do NOT want to validate the xml file, however, if a schema has been specified, then i want to validate the xml file. The problem is that the xml files are never validated regardless of whether or not an xml file has specified a schema. (I've also sabotaged a few xml files to deliberately introduce known errors into the xml so i can see if it has been validated).
Thanks for any information.
Edit:
I forgot to say which parser: Its Xerces 1.4 using the DOM Parser.
[This message has been edited by michael shea (edited November 11, 2001).]
 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
It seems only Xerces-J2 can validate an Xml against a Schema.
May be bcos Schema is relatively a new Standard. Pls visit the site http://xml.apache.org/xerces2-j/index.html for Xerces-Java 2.0.0 beta3 download & samples.
Regards,
Senthil
 
michael shea
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the reply. I actually may have the said the wrong version because we can validate against a schema. It works fine without the setFeature(dynamic, true) line in the code, except it validates all files, including those without schema's specified, which results in a whole bunch of errors being displayed)
 
michael shea
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actually the more i think about it, i realise that this may be a bug!?!? in the software. Could this be the case?
 
arul senthil
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
May be a bug.
If "http://xml.org/sax/features/validation" is set, then the Xml document MUST specify a grammar. i.e. a Schema file is necessary.But if "http://apache.org/xml/features/validation/dynamic" is set, then the Xml document is validated IF the grammar is specified.i.e. it depends on the Schema referral from Xml file.
Doesn't these two options appear complementary?
 
arul senthil
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I couldnt try any samples so far. Just see this page if it helps : http://xml.apache.org/xerces-j/schema.html
Regards,
Senthil
 
michael shea
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by arul senthil:

Doesn't these two options appear complementary?


Yes, good point but I've also tried that and it still doesn't work. I've also tried using the sample DOMCount.java that came in the Xerces package. It too has the same problem. Could it be because the schema is incorrectly declared in the xml file? Here is a sample:

 
arul senthil
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Xerces-j 1.4.x itself supports Schemas - sorry i didnt know that. A sample program i tried with Xerces-j 2.0.0 beta3 also gave the same problem.
The page http://www.apache.org/~edwingo/jaxp-faq.html says that :
Q: When I turn on validation, why do I fail to get any errors?
A: This is probably because you have not set an ErrorHandler. To get validation errors, three things must be true:
(1)The source document must be associated with a schema. For example, the source document contains a DOCTYPE declaration.
(2)Validation must be turned on.
(3)The application must set an ErrorHandler.
Often times, applications fail to perform the last item.
Any further improvements possible?
Regards,
Senthil
 
michael shea
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yep, I've set the errorHandler and it still has the same problem. I beginning to think that the Dynamic feature is not yet implemented. I may have to email the Xerces-J-User mailing list to see if anyone knows more about this.
[This message has been edited by michael shea (edited November 13, 2001).]
 
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am managing an XML Repository so validation is key for us. I tried Dynamic validation and it did not work either, I emailed IBM and they said it does not work in the 1.4.3:
Rob,
We had a bug in latest XML4j release, and that is why dynamic validation
was not working properly. We fixed the problem in Xerces (xml.apache.org)
however you will have to wait till next reference release of XML4J to get
this fix.

IBM Canada

I have not tried it since I found out that every XML file in the repository must have a grammar.
It is fixed, but where to find it I do not know...
 
michael shea
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Guys, just to let you know and anyone else who has run into the same problem. I updated the Xerces parser to the latest (1.4.4) and the dynamic feature works correctly as it should.
Thanks for all the help.
 
arul senthil
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Micheal
Can u share the sample code (or just a skeletal outline) with me?Pls send to agsenthil@lycos.com OR just paste here.
Thanks & Regards,
Senthil
 
michael shea
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Senthil, I'm not sure what code you wanted, but here is the code that I use and it dynamically validates xml files with the 1.4.4 parser.
 
arul senthil
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Michael
Thats what I wanted. Many thanks for that.
Regards,
Senthil
 
If you are using a rototiller, you are doing it wrong. Even on this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic