[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Java program for validating XML file with XSD - using Sun

  • To: "a.brillant" <public2@j...>, xml-dev@l...
  • Subject: Re: Java program for validating XML file with XSD - using Sun JRE 1.4.2_03
  • From: Mukul Gandhi <mukul_gandhi@y...>
  • 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@j...>

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

Regards,
Mukul

--- "a.brillant" <public2@j...> 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 

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2011 All Rights Reserved.