Hi Mukul, Thanks for your reply.
To answer all your queries, 1. My input xml is Response.xml 2. The xsd file is GenericSchema.xsd which has the WSDLSchema.xsd imported into it. All the 3 files, Response.xml, GeneriSchema.xsd, WSDLSchema.xsd are in my disk at the same location I am using eclipse version 3.4.1 So all the three files are directly in the project folder. 3. The code for performing the validation is as below: public static void main(String[] args) { System.out.println("in main class"); boolean status = false; SchemaValidator testXml = new SchemaValidator("Response.xml", "GenericSchema.xsd"); try { status = testXml.process(); if (status) { System.out.println("Response is OK."); } } catch (SAXParseException e) { //e.printStackTrace(); System.err.println("Validation failed\n" + e.getMessage() + "\nline " + e.getLineNumber() + ", column " + e.getColumnNumber() + "\n"); } catch (SAXException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } finally { //System.out.println(status); } } public class SchemaValidator { private String xmlFile = ""; private String xsdFile = ""; public SchemaValidator(String xmlFile, String xsdFile) { this.xmlFile = xmlFile; this.xsdFile = xsdFile; } public boolean process() throws SAXParseException, SAXException, Exception { boolean status = true; final String factoryImpl = System.getProperty("javax.xml.parsers.SAXParserFactory"); if (factoryImpl == null) { System.setProperty("javax.xml.parsers.SAXParserFactory", "org.apache.xerces.jaxp.SAXParserFactoryImpl"); } final SAXParserFactory factory = SAXParserFactory.newInstance(); factory.setNamespaceAware(true); factory.setValidating(true); factory.setFeature("http://xml.org/sax/features/validation", true); factory.setFeature(" http://apache.org/xml/features/validation/schema",true); factory.setFeature(" http://apache.org/xml/features/validation/schema-full-checking", true); final SAXParser parser = factory.newSAXParser(); System.out.println("the xsd file is: " + xsdFile); parser.setProperty(" http://apache.org/xml/properties/schema/external-schemaLocation", xsdFile); //parser.setProperty(" http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation", xsdFile); parser.parse(new FileInputStream(xmlFile), new DefaultHandler() { public void error(SAXParseException e) throws SAXException { final boolean status = false; throw e; } }); return status; } } 4. I am using Xerces-J version 2.9.1 Please do let me know if you require any other information from my side. Thanks in advance. Regards, Sneha On Fri, Jun 26, 2009 at 10:53 AM, Mukul Gandhi <gandhi.mu...@gmail.com>wrote: > Hi Sneha, > Could you please let us know: > > 1. What is your input XML (I guess it's Response.xml)? but please confirm.. > 2. What XSD document you are using to validate this XML? What is it's > location? > 3. How are you performing the validation? Do you use some API? If yes, > which API are you using? > 4. Which version of Xerces-J are you using? > > After we could know the answers to these questions, it would be easy > to reproduce the problem, and suggest something. > > On Thu, Jun 25, 2009 at 4:03 PM, Sneha Nikum<snehani...@gmail.com> wrote: > > Hi All, > > > > I am totally new to xerces. I am trying to validate a SOAP response > against > > its xsd files and am getting the error as > > cvc-elt.1: Cannot find the declaration of element 'SOAP-ENV:Envelope > > > > The Response .xml file is: > > <?xml version="1.0" encoding="ISO-8859-1"?> > > <SOAP-ENV:Envelope > > xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" > > xmlns:xsd="http://www.w3.org/2001/XMLSchema" > > xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" > > xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" > > > > > xsi:schemaLocation="file://home/sneha/WORK/workspace/WSDLConverter/WSDLSchema.xsd" > > namespace="urn:sms" > > > > > <SOAP-ENV:Body> > > <ns1:sendSMSToManyResponse xmlns:ns1="urn:SendSMSToMany"> > > <status xsi:type="xsd:string">invalid login</status> > > </ns1:sendSMSToManyResponse> > > </SOAP-ENV:Body> > > </SOAP-ENV:Envelope> > > > > GenericSchema.xsd > > > > <schema targetNamespace="http://schemas.xmlsoap.org/soap/envelope/" > > xsi:schemaLocation="http://schemas.xmlsoap.org/soap/envelope/" > > xmlns:tn="http://schemas.xmlsoap.org/soap/envelope/" > > xmlns:xsd="http://www.w3.org/2001/XMLSchema" > > xmlns="http://www.w3.org/2001/XMLSchema" > > xmlns:pr1="urn:sms"> > > <xsd:import > > > schemaLocation="file://home/sneha/WORK/workspace/WSDLConverter/WSDLSchema.xsd" > > namespace="urn:sms" /> > > > > <element name="Envelope" type="tn:EnvelopeType" /> > > <complexType name="EnvelopeType"> > > <sequence> > > <element name="Body" type="tn:BodyType" /> > > </sequence> > > </complexType> > > <complexType name="BodyType"> > > <choice> > > <element ref="pr1:sendSMSToManyRequest"/> > > <element ref="pr1:sendSMSToManyResponse"/> > > </choice> > > </complexType> > > </schema> > > > > WSDLSchema.xsd > > > > <xsd:schema targetNamespace="urn:sms" > > xmlns:xsd="http://www.w3.org/2001/XMLSchema" > > xmlns="http://www.w3.org/2001/XMLSchema"> > > <xsd:import namespace="http://schemas.xmlsoap.org/soap/encoding/" /> > > <xsd:import namespace="http://schemas.xmlsoap.org/wsdl/" /> > > <element name="sendSMSToManyRequest"> > > <complexType> > > <sequence> > > <element name="uid" type="xsd:string" /> > > <element name="pwd" type="xsd:string" /> > > <element name="phone" type="xsd:string" /> > > <element name="msg" type="xsd:string" /> > > </sequence> > > </complexType> > > </element> > > <element name="sendSMSToManyResponse"> > > <complexType> > > <sequence> > > <element name="status" type="xsd:string" /> > > </sequence> > > </complexType> > > </element> > > </xsd:schema> > > > > > > Also the code that I am using is the same as the one Gunni has written in > > the following link: > > http://forums.sun.com/thread.jspa?threadID=250998&start=15&tstart=0 > > > > I have looked on the net for various solutions for teh same, but have not > > yet been able to solve it. > > > > Please please please help. > > > > > > Thanks and Regards, > > -- > > Sneha > > > > -- > Regards, > Mukul Gandhi > > --------------------------------------------------------------------- > To unsubscribe, e-mail: j-users-unsubscr...@xerces.apache.org > For additional commands, e-mail: j-users-h...@xerces.apache.org > >