Hi Brenda, The error message you're getting complains about "OpenDNS" appearing in some document yet doesn't appear in any of the data you've shown. Such text doesn't just appear magically. There's some other document involved here that you haven't posted. It would help if you could make a connection between the error message you're getting and the input that you're feeding to Xerces and may also be useful to show us the stack trace rather than just mentioning that there was one. There should be information about the document's location (URL) in the SAXParseException in case you're not sure where to look for it.
Thanks. Michael Glavassevich XML Parser Development IBM Toronto Lab E-mail: mrgla...@ca.ibm.com E-mail: mrgla...@apache.org Brenda Coulson <bren...@dystech.com> wrote on 10/19/2009 12:10:54 PM: > Ok - I have been struggling with this for over two weeks now and am > about to pull out my hair. I have scrubbed discussion groups, > websites for help but alas I come up with nothing. I am trying to > validate an XML file against the XSD schema and running into some > problems. The XML I would like to validate is the payload of a web > service SOAP message. I am using the SAXParserFactory to generate my > parser and I am doing the following in my code to set up the parser: > > System.setProperty("javax.xml.validation.SchemaFactory:http://www. > w3.org/2001/XMLSchema", "org.apache.xerces.jaxp.validation.XMLSchemaFactory"); > > SAXParserFactory parserFactory = SAXParserFactory.newInstance(); > parserFactory.setNamespaceAware(true); > parserFactory.setValidating(false); > parserFactory.setFeature ("http://apache.org/xml/features/validation/schema > ", true); parserFactory.setFeature ("http://xml.org/sax/features/validation > ", true); > > SchemaFactory schemaFactory = SchemaFactory.newInstance("http: > //www.w3.org/2001/XMLSchema"); > StreamSource soapSchemaSource = new StreamSource(new > ClassPathResource(soapSchemaVersion).getInputStream()); > soapSchemaSource.setSystemId ("http://schemas.xmlsoap.org/soap/envelope/"); > > StreamSource schemaSource = new StreamSource(new > ClassPathResource("arm-internal.xsd").getInputStream());)); > schemaSource.setSystemId("http://service.arm.hud.gov/"); > > parserFactory.setSchema(schemaFactory.newSchema(new Source[] > {schemaSource, soapSchemaSource})); > > XMLReader reader = parserFactory.newSAXParser().getXMLReader(); > ArmHandler handler = new ArmHandler(); > reader.setErrorHandler(handler); > reader.parse(new InputSource(payload)); > > I get no errors setting up my schema but yet when I try to parse a > XML file using the schema specified in newSchema, I get the > following exception: > > "org.xml.sax.SAXParseException: s4s-elt-character: Non-whitespace > characters are not allowed in schema elements other than 'xs: > appinfo' and 'xs:documentation'. Saw 'OpenDNS'" > > It is followed by a stack trace. > My schema actually imports 2 external schemas and when I specify > their schema location as a URL, not a local file, it works but i can > not rely on that because I do not have access to the internet. > > I can attach my XML and XSD files but there is no place to do so. I > will add them at the end. > > Here are my questions/issues: > > 1. How do I solve the problem above from happening other than > relying on the internet to find the schema. > 2. When I do modify my XML file, the above exception is corrected > but then I get an error saying it can not resolve the soapenv namespace. > 3. Ultimately what I am interested in is getting the parser to > validate my XML correctly. It is intentionally flawed - there is a > bug in our system I am trying to correct. We were previously using > XMLValidator (from Spring) but it has no ability to > configure/customize so I switched to use the SAXParser. Ultimately, > I need the validator to complain when an element is missing. In my > XML below, I am missing the required element of referenceId but the > parser does not complain about it. Incidentally, it does not matter > if I supply the namespace or not in my XML file since I am > specifying the XSD in the application code in terms of it validating > the XML correctly. > > Thank you so much > Brenda