Try this, it works with Xerces and JDom:
import org.jdom.*;
import org.jdom.input.*;
import org.jdom.input.SAXBuilder;
import org.jdom.JDOMException;
import org.jdom.output.XMLOutputter;
import java.io.*;
import java.net.*;
public class TestXMLValidate {
public static void main(String[] args) {
String fileName = "sample.xml";
if (args.length > 0) {
fileName = args[0];
}
try {
File file = new File(fileName);
FileInputStream fis = new FileInputStream( file );
System.out.println("Making builder...");
SAXBuilder builder = new SAXBuilder(
"org.apache.xerces.parsers.SAXParser", true);
builder.setFeature(
"http://apache.org/xml/features/validation/schema", true);
System.out.println("Validating...");
System.out.println("Testing: " + file.toString());
builder.setProperty(
"http://apache.org/xml/properties/schema/" +
"external-schemaLocation",
"myschema " +
"http://localhost:8080/MySchemaLocation/myschema.xsd");
builder.build( fis );
System.out.println("\nXML Validated.\n");
} catch (Exception e) {
System.out.println("Validation failed: " + e.getMessage());
}
System.out.println("\nDone.");
}
}
> FWIW, I've asked this question in the ANT user list, but it seems that
> nobody over there knows how to do this either. I'm pretty convinced this
> is an XERCES related question.
>
> If I cannot get an ANT <xmlvalidate> specific reply, I will be glad to
> take a reply that points me to a sample java application that validates
> xml using a schema.
>
> Michael
>
>
>
>
> [EMAIL PROTECTED]
> 05/26/2004 02:35 PM
> Please respond to xerces-j-user
>
>
> To: [EMAIL PROTECTED]
> cc:
> Subject: How to validate XML using XSD schema with Apache
> ANT
>
>
> I have spent the better part of two days trying to figure out how to write
>
> an ANT <xmlvalidate> task that will use an XML schema for the validation.
> Is this possible using the currnent XALAN or XERCES release builds?
>
> If yes, does anyone have a working example of an ANT <xmlvalidate> task
> that uses XSD schema to validate?
>
> Michael Giroux
>
> ---------------------------------------------------------------------
> 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]
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]