Hi Shirsh, Thanks for the reply. But the problem is that the XSD is from an external entity and they don't have any targetNameSpace defined in their XSD file. In other words, it's not an value I can set/modify. To me, the problem looks like it's not even loading the entity resolver. I have some sysouts in my resolveEntity method in my entity resolver class, which are not being printed (it might be a dumb way to check if the method's called ...).
Also, I tried the case where I do not set the entity resolver on the parser. Instead I specified the XSD file location in the XML in this form: <RootElement xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceschemaLocation=\"C://tmp//xml//JetPayCCSchema.xsd\"> Even this case gives me the same error: cvc-elt.1: Cannot find the declaration of element 'RootElement'. I am not sure what I need to do to correct this... -Vamsi --- [EMAIL PROTECTED] wrote: > I am not sure why u need to use entity resolver..I am also new bee.. > I am using xerces 1.4.1 and i never used entity resolver.. > > I think u have not defined namespace in xsd file as wel as in your > xml.And thats why u have this problem. > > try this. > > In your xsd file, > <xs:schema targetNamespace="http://www.urcompany.com/something" > xmlns:xs="http://www.w3.org/2001/XMLSchema" > xmlns="http://www.urcompany.com/something" > elementFormDefault="qualified"> > > then in xml file, > <root xmlns="http://www.urcompany.com/something" > xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" > xsi:schemaLocation="http://www.urcompany.com/something > your_xsd_file.xsd"> > > So now u r xsd as well as xml have same default name space.and so when > the elements in xml are to be validated, the default name space will be > searched for the same as the elements are not qualified here(sp thy > belong to default namespace.) > And it should work.But u dont need to write entity resolver i think. > I am using following way to get instance of Parser. > > > XMLReader parser = > XMLReaderFactory.createXMLReader("org.apache.xerces.parsers.SAXParser"); > parser.setContentHandler(this); > parser.setErrorHandler(this); > > parser.setFeature("http://xml.org/sax/features/validation", true); > parser.setFeature( > > "http://apache.org/xml/features/validation/schema", > true); > parser.setFeature( > > "http://apache.org/xml/features/validation/schema-full-checking", > true); > parser.setFeature( > > "http://xml.org/sax/features/external-general-entities", > true); > parser.setFeature( > > "http://apache.org/xml/features/validation/schema/normalized-value", > true); > parser.parse(fileToValidate); > > HTH. > > regards, > Shirish > > > > > > -----Original Message----- > From: Vamsi Atluri [mailto:[EMAIL PROTECTED] > Sent: Tuesday, May 06, 2003 4:26 PM > To: [EMAIL PROTECTED] > Subject: Problem with XML Validation > > > Hi, > > I am using Xerces 2.4.0 for parsing XML files and validating the XML > against the schema file. I created an entity resolver class which loads > the XSD file from the local disk and returns it as an InputStream. I am > setting this entity resolver on the parser in this way: > > DOMParser parser = new org.apache.xerces.parsers.DOMParser(); > parser.setEntityResolver(new TestEntityResolver()); > parser.setFeature( "http://xml.org/sax/features/validation", true); > parser.setFeature( "http://xml.org/sax/features/namespaces", true); > parser.setFeature( "http://apache.org/xml/features/validation/schema", > true); > parser.setFeature( > "http://apache.org/xml/features/validation/schema-full-checking", true); > > My entity resolver's resolveEntity method works in this way: > > String xsdFile = "TestSchema.xsd"; > InputSource is = new InputSource(new FileReader(xsdFile)); > return is; > > I also created a small ErrorHandler that prints out any > SAXParseException > that it gets. > > Now, when I try to parse the XML string, I get the following error > printed > out by my ErrorHandler: > > cvc-elt.1: Cannot find the declaration of element 'RootElement'. > > The XML String I am trying to parse is of the form: > > <RootElement><Elem1>Data1</Elem1><Elem2>Data2</Elem2></RootElement> > > My XSD file has the following in the beginning of the XSD file: > > <?xml version="1.0" encoding="UTF-8"?> > > <xs:schema xmlns:xs = "http://www.w3.org/2001/XMLSchema" > elementFormDefault="unqualified" attributeFormDefault="unqualified"> > > And the RootElement is definitely defined in the XSD file. I ran a > search > for this error through google and some of the discussion boards said > that > there was a bug with older versions of Xerces, which is supposed to be > fixed. > > Any help would be grately appreciated. > > Thank you, > -Vamsi > > __________________________________ > Do you Yahoo!? > The New Yahoo! Search - Faster. Easier. Bingo. > http://search.yahoo.com > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > __________________________________ Do you Yahoo!? The New Yahoo! Search - Faster. Easier. Bingo. http://search.yahoo.com --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]