This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes XML and Related Technologies and the fly likes SAX parse and validate with XSD Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "SAX parse and validate with XSD" Watch "SAX parse and validate with XSD" New topic
Author

SAX parse and validate with XSD

Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
i am using SAX to parse a huge doc.
my Q is: How to set that Validation must occur?

The xerces parser I use seems to be only checking well-formedness, but noth validation ; although I force it to do so:

Approach 1:
in the root element of the XML Document.
PS:By default the XML Docs I receive do not have either noNamespaceSchemaLocation or schemaLocation set. so I added them manually programmatically just to be able to test; by using reader.set(..., ...);


Approach 2:
within the SAX Parser:

PS: THE TARGETNAMESPACE OF THE XSD DOC and the DEFAULT NAMESPACE OF THE RECEIVED Instance XML DOC ARE THE SAME; I guess this means I should NOT use noNamespaceSchemaLocation. Am I right?
also, xsi:schemaLocation="http://www.R�STEM.RU/XYZ.KUR file:/C:/schemas/schema1.xsd" this can or cannot exist in the XML Instance document. it should not make any difference. is this also correct?
In the Xerces web site, it claims when one programmatically defines the schema location, then the schemaLocation on the XML instance document (if ever exists) will be overwritten..


Thx
R�stem
[ January 26, 2005: Message edited by: R�stem-� Zal� ]
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
Have you tried leaving just one (1) space between "http://www.RUSTEM.RU/XYZ.KUR" and "XSDSchemaURI" for the "http://apache.org/xml/properties/schema/external-schemaLocation" property?


Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Originally posted by Lasse Koskela:
Have you tried leaving just one (1) space between "http://www.RUSTEM.RU/XYZ.KUR" and "XSDSchemaURI" for the "http://apache.org/xml/properties/schema/external-schemaLocation" property?


Thx, I solved the problem.
it was that in the web application I get the location of the XSD File using but the web application context name contained spaces, so it is interpreted as having more than 1 Namespaces and so accompanying schemas...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: SAX parse and validate with XSD
 
Similar Threads
Cannot find the declaration of element 'tns:MetricConfiguration'
Validating XML against Schema.
XML Schema parsing
XML Schema validation from java using Xercer 1.4.4 and DOM
xerces : Parsingproblem when "include" one or more Schema in another