Hi Sneha,
  I looked at the XML and XSD files, that you posted. I haven't looked
at deeply at the Java programs you posted.

When I perform XSD validation of your XML file with the Xerces-J
sample, jaxp.SourceValidator I get quite a few errors. Some of them
are related to improper use of namespaces.

I suggest, please first make sure, that your XML and the Schema are
correct at the XSD language level. You can use the Xerces-J utility
jaxp.SourceValidator to check that. I suggest please use the option -f
of this utility to enable full Schema checking.

After the validation passes with this utility, you can go into the
Java API details (after having a quick look at your Java programs, I
find them largely ok).

On Fri, Jun 26, 2009 at 11:08 AM, Sneha Nikum<snehani...@gmail.com> wrote:
> 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



-- 
Regards,
Mukul Gandhi

---------------------------------------------------------------------
To unsubscribe, e-mail: j-users-unsubscr...@xerces.apache.org
For additional commands, e-mail: j-users-h...@xerces.apache.org

Reply via email to