Trying to Validate using SAX [message #33841] |
Mon, 01 December 2003 12:48 ![Go to next message Go to next message](theme/Solstice/images/down.png) |
Eclipse User![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=) |
|
|
|
Originally posted by: svkk2.hotmail.com
I am trying to Validate a XML file against a XSD file. I am having errors
with the Schema and language Properties
import java.io.*;
import org.xml.sax.*;
import org.xml.sax.helpers.DefaultHandler;
import javax.xml.parsers.SAXParserFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
public class TestClass extends DefaultHandler
{
/* static final String JAXP_SCHEMA_LANGUAGE =
"http://java.sun.com/xml/jaxp/properties/schemaLanguage";
static final String W3C_XML_SCHEMA =
"http://www.w3.org/2001/XMLSchema";
static final String JAXP_SCHEMA_SOURCE =
"http://java.sun.com/xml/jaxp/properties/schemaSource";
*/
public static void main(String argv[])
{
try {
// Use an instance of ourselves as the SAX event handler
DefaultHandler handler = new TestClass();
// Use the validating parser
SAXParserFactory factory = SAXParserFactory.newInstance();
factory.setValidating(true);
factory.setNamespaceAware(true);
SAXParser saxParser = factory.newSAXParser();
saxParser.setProperty
("http://java.sun.com/xml/jaxp/properties/schemaLanguage",
"http://www.w3.org/2001/XMLSchema");
saxParser.setProperty
"http://java.sun.com/xml/jaxp/properties/schemaSource",
"file://C:/Program Files/Eclipse/iEngine2.1.xsd");
}catch (SAXParseException spe) {
// Error generated by the parser
System.out.println("\n** Parsing error"
+ ", line " + spe.getLineNumber()
+ ", uri " + spe.getSystemId());
System.out.println(" " + spe.getMessage() );
// Use the contained exception, if any
Exception x = spe;
if (spe.getException() != null)
x = spe.getException();
x.printStackTrace();
} catch (SAXException sxe) {
// Error generated by this application
// (or a parser-initialization error)
Exception x = sxe;
if (sxe.getException() != null)
x = sxe.getException();
x.printStackTrace();
} catch (ParserConfigurationException pce) {
// Parser with specified options can't be built
pce.printStackTrace();
} //catch (IOException ioe) {
// I/O error
//ioe.printStackTrace();
//}
System.exit(0);
}
}
This code is giving me the following errors
org.xml.sax.SAXNotRecognizedException: Property:
http://java.sun.com/xml/jaxp/properties/schemaLanguage
at org.apache.crimson.parser.XMLReaderImpl.setProperty(Unknown Source)
at org.apache.crimson.jaxp.SAXParserImpl.setProperty(Unknown Source)
at testPack.TestClass.main(TestClass.java:54)
I have checked the Sun's website for explanation but nothing helps. Anyone
can figure out what the error is? Does my classpath have to be set to
something specific, or are there any external libraries to be included?
|
|
|
Re: Trying to Validate using SAX [message #33876 is a reply to message #33841] |
Mon, 01 December 2003 14:27 ![Go to previous message Go to previous message](theme/Solstice/images/up.png) |
Eclipse User![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=) |
|
|
|
Originally posted by: merks.ca.ibm.com
Soni,
This forum for questions about the XSD model, not about how to use validating
parsers. Perhaps these properties are things that need to be set using
SAXParserFactory.setFeature before you create the parser...
Soni wrote:
> I am trying to Validate a XML file against a XSD file. I am having errors
> with the Schema and language Properties
>
> import java.io.*;
>
> import org.xml.sax.*;
> import org.xml.sax.helpers.DefaultHandler;
>
> import javax.xml.parsers.SAXParserFactory;
> import javax.xml.parsers.ParserConfigurationException;
> import javax.xml.parsers.SAXParser;
>
> public class TestClass extends DefaultHandler
> {
>
> /* static final String JAXP_SCHEMA_LANGUAGE =
> "http://java.sun.com/xml/jaxp/properties/schemaLanguage";
>
> static final String W3C_XML_SCHEMA =
> "http://www.w3.org/2001/XMLSchema";
> static final String JAXP_SCHEMA_SOURCE =
> "http://java.sun.com/xml/jaxp/properties/schemaSource";
> */
>
> public static void main(String argv[])
> {
> try {
> // Use an instance of ourselves as the SAX event handler
> DefaultHandler handler = new TestClass();
> // Use the validating parser
> SAXParserFactory factory = SAXParserFactory.newInstance();
> factory.setValidating(true);
> factory.setNamespaceAware(true);
> SAXParser saxParser = factory.newSAXParser();
> saxParser.setProperty
>
> ("http://java.sun.com/xml/jaxp/properties/schemaLanguage",
> "http://www.w3.org/2001/XMLSchema");
> saxParser.setProperty
> "http://java.sun.com/xml/jaxp/properties/schemaSource",
> "file://C:/Program Files/Eclipse/iEngine2.1.xsd");
> }catch (SAXParseException spe) {
> // Error generated by the parser
> System.out.println("\n** Parsing error"
> + ", line " + spe.getLineNumber()
> + ", uri " + spe.getSystemId());
> System.out.println(" " + spe.getMessage() );
>
> // Use the contained exception, if any
> Exception x = spe;
> if (spe.getException() != null)
> x = spe.getException();
> x.printStackTrace();
>
> } catch (SAXException sxe) {
> // Error generated by this application
> // (or a parser-initialization error)
> Exception x = sxe;
> if (sxe.getException() != null)
> x = sxe.getException();
> x.printStackTrace();
>
> } catch (ParserConfigurationException pce) {
> // Parser with specified options can't be built
> pce.printStackTrace();
>
> } //catch (IOException ioe) {
> // I/O error
> //ioe.printStackTrace();
> //}
>
> System.exit(0);
> }
> }
>
> This code is giving me the following errors
>
> org.xml.sax.SAXNotRecognizedException: Property:
> http://java.sun.com/xml/jaxp/properties/schemaLanguage
> at org.apache.crimson.parser.XMLReaderImpl.setProperty(Unknown Source)
> at org.apache.crimson.jaxp.SAXParserImpl.setProperty(Unknown Source)
> at testPack.TestClass.main(TestClass.java:54)
>
> I have checked the Sun's website for explanation but nothing helps. Anyone
> can figure out what the error is? Does my classpath have to be set to
> something specific, or are there any external libraries to be included?
|
|
|
Re: Trying to Validate using SAX [message #581293 is a reply to message #33841] |
Mon, 01 December 2003 14:27 ![Go to previous message Go to previous message](theme/Solstice/images/up.png) |
Ed Merks![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=ed.merks%40gmail.com) Messages: 33264 Registered: July 2009 |
Senior Member |
|
|
Soni,
This forum for questions about the XSD model, not about how to use validating
parsers. Perhaps these properties are things that need to be set using
SAXParserFactory.setFeature before you create the parser...
Soni wrote:
> I am trying to Validate a XML file against a XSD file. I am having errors
> with the Schema and language Properties
>
> import java.io.*;
>
> import org.xml.sax.*;
> import org.xml.sax.helpers.DefaultHandler;
>
> import javax.xml.parsers.SAXParserFactory;
> import javax.xml.parsers.ParserConfigurationException;
> import javax.xml.parsers.SAXParser;
>
> public class TestClass extends DefaultHandler
> {
>
> /* static final String JAXP_SCHEMA_LANGUAGE =
> "http://java.sun.com/xml/jaxp/properties/schemaLanguage";
>
> static final String W3C_XML_SCHEMA =
> "http://www.w3.org/2001/XMLSchema";
> static final String JAXP_SCHEMA_SOURCE =
> "http://java.sun.com/xml/jaxp/properties/schemaSource";
> */
>
> public static void main(String argv[])
> {
> try {
> // Use an instance of ourselves as the SAX event handler
> DefaultHandler handler = new TestClass();
> // Use the validating parser
> SAXParserFactory factory = SAXParserFactory.newInstance();
> factory.setValidating(true);
> factory.setNamespaceAware(true);
> SAXParser saxParser = factory.newSAXParser();
> saxParser.setProperty
>
> ("http://java.sun.com/xml/jaxp/properties/schemaLanguage",
> "http://www.w3.org/2001/XMLSchema");
> saxParser.setProperty
> "http://java.sun.com/xml/jaxp/properties/schemaSource",
> "file://C:/Program Files/Eclipse/iEngine2.1.xsd");
> }catch (SAXParseException spe) {
> // Error generated by the parser
> System.out.println("\n** Parsing error"
> + ", line " + spe.getLineNumber()
> + ", uri " + spe.getSystemId());
> System.out.println(" " + spe.getMessage() );
>
> // Use the contained exception, if any
> Exception x = spe;
> if (spe.getException() != null)
> x = spe.getException();
> x.printStackTrace();
>
> } catch (SAXException sxe) {
> // Error generated by this application
> // (or a parser-initialization error)
> Exception x = sxe;
> if (sxe.getException() != null)
> x = sxe.getException();
> x.printStackTrace();
>
> } catch (ParserConfigurationException pce) {
> // Parser with specified options can't be built
> pce.printStackTrace();
>
> } //catch (IOException ioe) {
> // I/O error
> //ioe.printStackTrace();
> //}
>
> System.exit(0);
> }
> }
>
> This code is giving me the following errors
>
> org.xml.sax.SAXNotRecognizedException: Property:
> http://java.sun.com/xml/jaxp/properties/schemaLanguage
> at org.apache.crimson.parser.XMLReaderImpl.setProperty(Unknown Source)
> at org.apache.crimson.jaxp.SAXParserImpl.setProperty(Unknown Source)
> at testPack.TestClass.main(TestClass.java:54)
>
> I have checked the Sun's website for explanation but nothing helps. Anyone
> can figure out what the error is? Does my classpath have to be set to
> something specific, or are there any external libraries to be included?
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Powered by
FUDForum. Page generated in 0.03052 seconds