Return-Path: Delivered-To: apmail-xerces-j-users-archive@www.apache.org Received: (qmail 67194 invoked from network); 20 Jul 2005 04:06:31 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 20 Jul 2005 04:06:31 -0000 Received: (qmail 38905 invoked by uid 500); 20 Jul 2005 04:06:30 -0000 Delivered-To: apmail-xerces-j-users-archive@xerces.apache.org Received: (qmail 38375 invoked by uid 500); 20 Jul 2005 04:06:28 -0000 Mailing-List: contact j-users-help@xerces.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: j-users@xerces.apache.org Delivered-To: mailing list j-users@xerces.apache.org Received: (qmail 38362 invoked by uid 99); 20 Jul 2005 04:06:28 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 19 Jul 2005 21:06:28 -0700 X-ASF-Spam-Status: No, hits=0.8 required=10.0 tests=DNS_FROM_RFC_ABUSE,SPF_HELO_FAIL X-Spam-Check-By: apache.org Received-SPF: pass (asf.osuosl.org: local policy) Received: from [32.97.182.144] (HELO e4.ny.us.ibm.com) (32.97.182.144) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 19 Jul 2005 21:06:23 -0700 Received: from d01relay02.pok.ibm.com (d01relay02.pok.ibm.com [9.56.227.234]) by e4.ny.us.ibm.com (8.12.11/8.12.11) with ESMTP id j6K46P7I022928 for ; Wed, 20 Jul 2005 00:06:25 -0400 Received: from d01av04.pok.ibm.com (d01av04.pok.ibm.com [9.56.224.64]) by d01relay02.pok.ibm.com (8.12.10/NCO/VERS6.7) with ESMTP id j6K46PGH253282 for ; Wed, 20 Jul 2005 00:06:25 -0400 Received: from d01av04.pok.ibm.com (loopback [127.0.0.1]) by d01av04.pok.ibm.com (8.12.11/8.13.3) with ESMTP id j6K46PYa011115 for ; Wed, 20 Jul 2005 00:06:25 -0400 Received: from d25ml03.torolab.ibm.com (d25ml03.torolab.ibm.com [9.26.6.104]) by d01av04.pok.ibm.com (8.12.11/8.12.11) with ESMTP id j6K46Ppx011108 for ; Wed, 20 Jul 2005 00:06:25 -0400 In-Reply-To: <20050720031534.19303.qmail@web52813.mail.yahoo.com> To: j-users@xerces.apache.org MIME-Version: 1.0 Subject: Re: Parsing XML file using XSD validation X-Mailer: Lotus Notes Release 6.0.2CF1 June 9, 2003 Message-ID: From: Michael Glavassevich Date: Wed, 20 Jul 2005 00:06:23 -0400 X-MIMETrack: Serialize by Router on D25ML03/25/M/IBM(Release 6.5.4|March 27, 2005) at 07/20/2005 00:06:25, Serialize complete at 07/20/2005 00:06:25 Content-Type: text/plain; charset="US-ASCII" X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Hi Anthony, You've enabled both schema [1] and DTD [2] validation. Since your document doesn't contain a DOCTYPE, I assume you didn't want to turn on DTD validation. You can fix this by removing documentBuilderFactory.setValidating(true) from your code. Thanks. [1] http://xml.apache.org/xerces2-j/javadocs/api/javax/xml/parsers/DocumentBuilderFactory.html#setSchema(javax.xml.validation.Schema) [2] http://xml.apache.org/xerces2-j/javadocs/api/javax/xml/parsers/DocumentBuilderFactory.html#setValidating(boolean) "Anthony N. Frasso" wrote on 07/19/2005 11:15:34 PM: > Hello, and thanks in advance for all of your help. > > I am currently using Xerces (for Java) version 2.7 with the J2SE 1.4.2 > on Mac OS X version 10.3. > > I am attempting to parse an XML file while validating it against an > XSD. > > Here is my code to parse the XML file: > > > SchemaFactory schemaFactory = > SchemaFactory.newInstance( > XMLConstants.W3C_XML_SCHEMA_NS_URI); > Schema schema = > schemaFactory.newSchema(new File("playlist.xsd")); > System.out.println("Schema: " + schema); > > DocumentBuilderFactory documentBuilderFactory = > DocumentBuilderFactory.newInstance(); > System.out.println("Factory: " + documentBuilderFactory); > documentBuilderFactory.setSchema(schema); > documentBuilderFactory.setValidating(true); > documentBuilderFactory.setNamespaceAware(true); > > DocumentBuilder documentBuilder = > documentBuilderFactory.newDocumentBuilder(); > System.out.println("Builder: " + documentBuilder); > documentBuilder.setErrorHandler(new PlaylistParserErrorHandler()); > documentBuilder.parse(new File("episodes.xml")); > > > playlist.xsd looks like the following: > > > > targetNamespace="http://www.gafungi.com" > xmlns="http://www.gafungi.com" > elementFormDefault="qualified" > attributeFormDefault="qualified"> > > > > type="xs:anyURI" > minOccurs="1"/> > > > > > > type="movieType" > minOccurs="0" > maxOccurs="unbounded" /> > > > > type="playlistType" /> > > > > and episodes.xml looks like: > > > > xsi:schemaLocation="http://www.gafungi.com playlist.xsd" > xmlns="http://www.gafungi.com"> > > > /Users/tony/Movies/1.avi > > > /Users/tony/Movies/2.avi > > > /Users/tony/Movies/3.avi > > > /Users/tony/Movies/4.avi > > > /Users/tony/Movies/5.avi > > > /Users/tony/Movies/6.avi > > > /Users/tony/Movies/7.avi > > > > > When I attempt to run my code, I get the following exception: > > org.xml.sax.SAXParseException: Document is invalid: no grammar found. > at org.apache.xerces.util.ErrorHandlerWrapper. > createSAXParseException(Unknown Source) > at org.apache.xerces.util.ErrorHandlerWrapper. > error(Unknown Source) > at org.apache.xerces.impl.XMLErrorReporter. > reportError(Unknown Source) > at org.apache.xerces.impl.XMLErrorReporter. > reportError(Unknown Source) > at org.apache.xerces.impl.XMLNSDocumentScannerImpl. > scanStartElement(Unknown Source) > at org.apache.xerces.impl.XMLNSDocumentScannerImpl > $NSContentDispatcher.scanRootElementHook(Unknown Source) > at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl > $FragmentContentDispatcher.dispatch(Unknown Source) > at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl. > scanDocument(Unknown Source) > at org.apache.xerces.parsers.XML11Configuration. > parse(Unknown Source) > at org.apache.xerces.parsers.XML11Configuration. > parse(Unknown Source) > at org.apache.xerces.parsers.XMLParser.parse(Unknown Source) > at org.apache.xerces.parsers.DOMParser.parse(Unknown Source) > at org.apache.xerces.jaxp.DocumentBuilderImpl. > parse(Unknown Source) > at javax.xml.parsers.DocumentBuilder. > parse(Unknown Source) > > Any clue what is failing here, and what the exception means? > > Regards, > Anthony Frasso > > __________________________________________________ > Do You Yahoo!? > Tired of spam? Yahoo! Mail has the best spam protection around > http://mail.yahoo.com > > --------------------------------------------------------------------- > To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org > For additional commands, e-mail: j-users-help@xerces.apache.org > Michael Glavassevich XML Parser Development IBM Toronto Lab E-mail: mrglavas@ca.ibm.com E-mail: mrglavas@apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org For additional commands, e-mail: j-users-help@xerces.apache.org