OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.


Help: OASIS Mailing Lists Help | MarkMail Help



   RE: [xml-dev] problem with noNamespaceSchemaLocation.....urgent ! !!

[ Lists Home | Date Index | Thread Index ]

Alright, here it is:

	public static void main( String argv[] )
		throws ParserConfigurationException, SAXException,
FileNotFoundException, IOException
		File inFile = new File( "d:\\xml\\schemas\\order.xml" );
		InputStream is = new FileInputStream( inFile );
		InputSource input = new InputSource( is );
		ContentHandler handler = new OrderReporter();
		SAXParserFactory parserFactory =
// do these work?
		parserFactory.setNamespaceAware(true);			// ?
		SAXParser parser = parserFactory.newSAXParser();
		XMLReader reader = parser.getXMLReader();
		//reader.setErrorHandler(new DefaultHandler());
 		try {
reader.setFeature("http://apache.org/xml/features/validation/schema";, true);
cking", true);
paceSchemaLocation", "file:///d:/xml/schemas/order.xsd");
        catch (SAXException e) {

		reader.setContentHandler( handler );
		reader.parse( input );


This is just the main() function. The rest is left as an exercise for the

I don't know if the parser factory settings are redundant or not.

When this is run, errors are reported by a "default" error handler. You're
suppose to set the real error handler by the commented out method
reader.setErrorHandler(new DefaultHandler()). The reason that this is
commented out is because the DefaultHandler() will NOT report errors that
occurred. This may be why my 1.4.1 version wasn't reporting errors, you
think? You'll eventually want to derive you're own ErrorHandler class from
the DefaultHandler, making sure you report all your errors. 

Here's the output I got, which has the errors mixed in with stdout stuff:

Items for Order #1:

Warning: validation was turned on but an org.xml.sax.ErrorHandler was not
set, which is probably not what is desired.  Parser will use a default
ErrorHandler to print the first 10 errors.  Please call
the 'setErrorHandler' method to fix this.
Error: URI=null Line=8: cvc-type.3.1.3: The value '1111 2222 333 1111' of
element 'CardNo' is not valid.
Error: URI=null Line=12: cvc-complex-type.2.4.a: Invalid content starting
with element 'Ttle'. The content must match '((((""
Qty. 1
Turtle Dove,             Qty. 2
French Hen,              Qty. 3
Error: URI=null Line=32: cvc-type.3.1.3: The value '17.22' of element
'UnitPrice' is not valid.
Calling Bird,            Qty. 4
Golden Ring,             Qty. 5
Press any key to continue...


News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 2001 XML.org. This site is hosted by OASIS