OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

 


 

   Re: [xml-dev] Java program for validating XML file with XSD - using Sun

[ Lists Home | Date Index | Thread Index ]
  • To: "a.brillant" <public2@japisoft.com>, xml-dev@lists.xml.org
  • Subject: Re: [xml-dev] Java program for validating XML file with XSD - using Sun JRE 1.4.2_03
  • From: Mukul Gandhi <mukul_gandhi@yahoo.com>
  • Date: Thu, 14 Jul 2005 04:23:46 -0700 (PDT)
  • Domainkey-signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=Message-ID:Received:Date:From:Subject:To:In-Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding; b=h8381f8CCBA1p/UyL5ZbjXSt+FYgxh6CVW5Wwxq6Tz3gq+VpWFC9B2waCWRX5VMYTOtBTFVxFEqJqA77YsVWGrRhdbnlcPPBG3CGT2j/+l4dbL0Uh6UjyeBfBgNh6sunwFzqqEhXlkZ2rN8Ve4IqHDhBzDZPy8wa4ytvzuUqUN4= ;
  • In-reply-to: <42D4DD9B.7030107@japisoft.com>

Thank you. It works. Now my program is working fine. I
am using Xerces-J.

Regards,
Mukul

--- "a.brillant" <public2@japisoft.com> wrote:

> Hi,
> 
> try this for letting the parser working with W3C
> Schema :
> 
> factory.setAttribute(
>             
>
"http://java.sun.com/xml/jaxp/properties/schemaLanguage";,
>              "http://www.w3.org/2001/XMLSchema";);
> 
> Best regards,
> 
> A.Brillant
> --------------------------------------------------
> EditiX : XML Editor and XSLT Debugger
> http://www.editix.com
> --------------------------------------------------
> 
> Mukul Gandhi wrote:
> 
> >I have XML and XSD files as below:
> >
> >XML file
> >--------
> ><?xml version="1.0" encoding="ISO-8859-1"?>
> ><shiporder orderid="889923"
>
>xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
> 
> >                          
> >xsi:noNamespaceSchemaLocation="shiporder.xsd">
> > <orderperson>John Smith</orderperson>
> > <shipto>
> >  <name>Ola Nordmann</name>
> >........ etc
> >
> >XSD file
> >--------
> ><?xml version="1.0" encoding="ISO-8859-1" ?>
> ><xs:schema
> >xmlns:xs="http://www.w3.org/2001/XMLSchema";>
> ><xs:element name="shiporder">
> > <xs:complexType>
> >  <xs:sequence>
> >   <xs:element name="orderperson"
> type="xs:string"/>
> >   <xs:element name="shipto">
> >    <xs:complexType>
> >     <xs:sequence>
> >........ etc
> >
> >Java program is
> >---------------
> >import javax.xml.parsers.DocumentBuilder;
> >import javax.xml.parsers.DocumentBuilderFactory;
> >import javax.xml.parsers.FactoryConfigurationError;
> >import
> javax.xml.parsers.ParserConfigurationException;
> >
> >import org.xml.sax.SAXException;
> >import org.xml.sax.SAXParseException;
> >
> >import java.io.File;
> >import java.io.IOException;
> >
> >import org.w3c.dom.Document;
> >import org.w3c.dom.DOMException;
> >
> >public class ValidateWithSchema {
> >
> >    static Document document;
> >
> >    public static void main(String argv[])
> >    {
> >        if (argv.length != 1) {
> >            System.err.println("Usage: java
> >ValidateWithSchema filename");
> >            System.exit(1);
> >        }
> >
> >        DocumentBuilderFactory factory =
> >DocumentBuilderFactory.newInstance();
> >        factory.setValidating(true);
> >        factory.setNamespaceAware(true);
> >        try {
> >           DocumentBuilder builder =
> >factory.newDocumentBuilder();
> >           document = builder.parse(new
> >File(argv[0]));
> >        } catch (SAXException sxe) {
> >
> >           Exception  x = sxe;
> >           if (sxe.getException() != null)
> >               x = sxe.getException();
> >           x.printStackTrace();
> >
> >        } catch (ParserConfigurationException pce)
> {
> >
> >            pce.printStackTrace();
> >
> >        } catch (IOException ioe) {
> >
> >           ioe.printStackTrace();
> >        }
> >    }
> >
> >}
> >
> >When I run the program as following -
> >
> >C:\xml>java ValidateWithSchema shiporder.xml
> >
> >Warning: validation was turned on but an
> >org.xml.sax.ErrorHandler was not
> >set, which is probably not what is desired.  Parser
> >will use a default
> >ErrorHandler to print the first 10 errors.  Please
> >call
> >the 'setErrorHandler' method to fix this.
> >Error: URI=file:///C:/xml/shiporder.xml Line=2:
> >Document is invalid: no grammar
> >found.
> >Error: URI=file:///C:/xml/shiporder.xml Line=2:
> >Document root element "shiporder
> >", must match DOCTYPE root "null".
> >
> >The error comes as shown above..
> >
> >Can someone please tell where is the problem?
> >
> >Regards,
> >Mukul
> >
> >
> >
> >	
> >		
> >__________________________________ 
> >Do you Yahoo!? 
> >Yahoo! Mail - You care about security. So do we. 
> >http://promotions.yahoo.com/new_mail
> >
>
>-----------------------------------------------------------------
> >The xml-dev list is sponsored by XML.org
> <http://www.xml.org>, an
> >initiative of OASIS <http://www.oasis-open.org>
> >
> >The list archives are at
> http://lists.xml.org/archives/xml-dev/
> >
> >To subscribe or unsubscribe from this list use the
> subscription
> >manager:
> <http://www.oasis-open.org/mlmanage/index.php>
> >
> >
> >  
> >
> 
> 
> 
>
-----------------------------------------------------------------
> The xml-dev list is sponsored by XML.org
> <http://www.xml.org>, an
> initiative of OASIS <http://www.oasis-open.org>
> 
> The list archives are at
> http://lists.xml.org/archives/xml-dev/
> 
> To subscribe or unsubscribe from this list use the
> subscription
> manager:
> <http://www.oasis-open.org/mlmanage/index.php>
> 
> 


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 




 

News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 2001 XML.org. This site is hosted by OASIS