Thanks a lot Vijaya. i managed to compile and run successfully the java code you sent. works perfect. my next question is: schema file for the xml is not defined in the xml file so i added the property '...external-noName...' in which i can define the external schema file to validate. works perfect. now, is it possible to cache this schema file, so that i dont have to read it all the time i need to validate xml?? is so then how? thanks a million once again. tom
--- Vijaya Kumar <[EMAIL PROTECTED]> wrote: > > Hi John > > definately i will do that, > u can send those files as attachment, i will try to > execute it. > > i am sending one java file as attachment which will > validate the xml > file > aganist the schema using xerces. u can refer that > > Vijay > > -----Original Message----- > From: tom john [mailto:[EMAIL PROTECTED] > Sent: Monday, April 08, 2002 6:57 PM > To: [EMAIL PROTECTED] > Subject: RE: xml validation with schema ERROR > > > Hi Vijaya Kumar, > thanks a lot for your response. I am usuing > xerces2.0. > isnt it the latest version. if it is, can you try to > compile and run it in your system? (i can send it if > you need as an attachment) > thanks a lot again > > > --- Vijaya Kumar <[EMAIL PROTECTED]> > wrote: > > > > One possibality of getting this error message > > because u may be using the > > old version of Xerces, so download the latest > > version of Xerces > > and keep the new xerces.jar in ur classpath. > > > > i think this will solve ur problem > > > > Regards > > Vijay > > > > -----Original Message----- > > From: tom john [mailto:[EMAIL PROTECTED] > > Sent: Thursday, April 04, 2002 4:06 PM > > To: [EMAIL PROTECTED] > > Subject: xml validation with schema ERROR > > > > > > Hi, > > I am new validating xml with schema. I get the > > following error message when i try to validate > xml: > > > > org.xml.sax.SAXNotRecognizedException: > > http://apache.org/xml/feature > > s/validation/schema-full-checking > > Error: org.xml.sax.SAXParseException: Document > root > > element "PERSON > > ", must match DOCTYPE root "null". > > Error: org.xml.sax.SAXParseException: Document is > > invalid: no gramm > > ar found. > > java.lang.NullPointerException > > > > I know the xml document i have is valid. > > the xml i have is: > > > > <?xml version="1.0" encoding="UTF-8"?> > > <PERSON NAME="XXX" > > > xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" > > xsi:noNamespaceSchemaLocation="mySchema.xsd"> > > <COUNTRY>countryName</COUNTRY> > > <COUNTRY>countryName</COUNTRY> > > </PERSON> > > > > schema for it is: > > > > <?xml version="1.0" encoding="UTF-8"?> > > <xs:schema > > xmlns:xs="http://www.w3.org/2001/XMLSchema" > > elementFormDefault="qualified"> > > <xs:element name="PERSON"> > > <xs:complexType> > > <xs:sequence> > > <xs:element name="COUNTRY" > > type="xs:string" > > maxOccurs="unbounded"/> > > </xs:sequence> > > <xs:attribute name="NAME" type="xs:string" > > use="required"/> > > </xs:complexType> > > </xs:element> > > </xs:schema> > > > > The code i am using to validate is: > > > > import org.apache.xerces.parsers.DOMParser; > > import org.apache.xerces.parsers.SAXParser; > > import org.xml.sax.ErrorHandler; > > import org.xml.sax.SAXException; > > import org.xml.sax.SAXParseException; > > import org.xml.sax.SAXNotRecognizedException; > > import org.xml.sax.SAXNotSupportedException; > > import java.io.IOException; > > > > import java.io.File; > > > > // A Valdating DOM Application > > // with registered Error Handlers > > public class SchemaValidate implements > ErrorHandler > > { > > > > // Constructor > > public SchemaValidate (String xmlFile) { > > > > // Create a Xerces DOM Parser > > DOMParser parser = new DOMParser(); > > //SAXParser parser = new SAXParser(); > > //MyResolver resolver = new MyResolver(); > > > > // Turn Validation on > > try { > > > > > parser.setFeature("http://xml.org/sax/features/validation", > > true); > > > > > //parser.setProperty("http://apache.org/xml/properties/schema/external-n > > oNamespaceSchemaLocation", > > "ebxml.xsd"); > > > > //parser.setEntityResolver(resolver); > > > > > parser.setFeature("http://apache.org/xml/features/validation/schema",fal > > se); > > > > > parser.setFeature("http://apache.org/xml/features/validation/schema-full > > -checking",false); > > > > > parser.setFeature("http://apache.org/xml/features/validation/dtd",false) > > ; > > } > > catch (SAXNotRecognizedException e) { > > System.err.println (e); > > } > > catch (SAXNotSupportedException e) { > > System.err.println (e); > > } > > > > // Register Error Handler > > parser.setErrorHandler (this); > > > > // Parse the Document > > try { > > parser.parse(xmlFile); > > } > > catch (SAXException e) { > > System.err.println (e); > > } > > catch (IOException e) { > > System.err.println (e); > > } > > catch (Exception e) { > > System.err.println (e); > > } > > > > } > > > > // Warning Event Handler > > public void warning (SAXParseException e) > > throws SAXException { > > System.err.println ("Warning: "+e); > > } > > > > // Error Event Handler > > public void error (SAXParseException e) > > throws SAXException { > > System.err.println ("Error: "+e); > > } > > > > // Fatal Error Event Handler > > public void fatalError (SAXParseException e) > > throws SAXException { > > System.err.println ("Fatal Error: "+e); > > } > > > > // Main Method > > public static void main (String[] args) { > > SchemaValidate validatingDOM = new > > SchemaValidate("D:\\tmp\\myxml.xml"); > > } > === message truncated === > ATTACHMENT part 2 application/octet-stream name=TRPSchemaValidater.java > --------------------------------------------------------------------- > To unsubscribe, e-mail: > [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] __________________________________________________ Do You Yahoo!? Yahoo! Tax Center - online filing with TurboTax http://taxes.yahoo.com/ --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
