Try this:
private static final String PARSER_NAME =
"org.apache.xerces.parsers.SAXParser";
private static boolean setValidation = true;
private static boolean setNameSpaces = true;
private static boolean setLoadExternalDTD = true;
private static boolean setSchemaSupport = true;
private static boolean setSchemaFullSupport = false;
XMLReader xr;
try {
// Create the XML reader...
xr = XMLReaderFactory.createXMLReader(PARSER_NAME);
}
catch (Exception e) {
// Handle the exception
}
// Set Parser features
try {
// Activate/Deactivate Parser Validation
xr.setFeature("http://xml.org/sax/features/validation",
setValidation);
// Activate/Deactivate Namespace Support
xr.setFeature("http://xml.org/sax/features/namespaces",
setNameSpaces);
// Activate/Deactivate XML Schema support
xr.setFeature("http://apache.org/xml/features/validation/schema",
setSchemaSupport);
// Activate/Deactivate Schema Full Support
xr.setFeature("http://apache.org/xml/features/validation/schema-full-checkin
g", setSchemaFullSupport);
}
catch (SAXException e) {
// Handle the exception
}
try {
// Set the ContentHandler...
xr.setContentHandler("your handler");
xr.setErrorHandler("your handler");
xr.parse( XML );
}
catch (SAXException e) {
// Handle the exception
}
Hope this helps...
Arturo Ma
-------------------------------------------------------------
Arturo Ma
[EMAIL PROTECTED]
FGM Inc.
2820 Camino Del Rio South, Suite 130
San Diego, CA 92108
Office: 619. 297.2905
Fax: 619. 297.2923
http://www.fgm.com
----- Original Message -----
From: "Thomas Bierhance" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Friday, December 14, 2001 10:18 AM
Subject: Schema validating XML parsing
> Hello xerces-j-user,
>
> I just started using Xerces (1.4.4) and have a problem parsing a XML
> that is assigned to an XML Schema. I had a look on the SAXCounter
> example, that succeeds in validating my Files (XML Spy does as
> well), but it is using deprecated API. So I tried to do it a
> different way...
>
> SAXParserFactory parserFactory = SAXParserFactory.newInstance();
> parserFactory.setValidating(true);
>
> File f = new File("E:/Projekte/sampleDoku.xml");
>
> try {
> SAXParser parser = parserFactory.newSAXParser();
> parser.parse(f, new MyHandler());
> } catch (Exception e) {
> e.printStackTrace();
> }
>
> "MyHandler" extends "DefaultHandler" and gives error msg like...
>
> [Warning] Valid documents must have a <!DOCTYPE declaration.
> [Error] Element type "moduledescription" is not declared.
> [Error] Attribute "xmlns:xsi" is not declared for element
"moduledescription".
> [Error] Attribute "xsi:noNamespaceSchemaLocation" is not declared for
element "moduledescription".
>
> That looks to me like my schema is not found.
>
> What is going on here, where is my fault? What is the official (not
> deprecated) way to do this using the JAXP interfaces?
>
> --
> Regards and Thanks,
>
> Thomas mailto:[EMAIL PROTECTED]
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]