Java XML Schema validation
Hi all,
I had problem of validating XML instance with Schema using java and xerces release 1.4.1.
It seems that the SAXParser only supports DTD, not Schema. The DOMParser, will not even try to validate even though the
parser.setFeature( "http://apache.org/xml/features/validation/schema", true );
parser.setFeature( "http://xml.org/sax/features/validation", true );
were called.
Any suggestion? Maybe sample code that works.
Thank you in advance.
[503 byte] By [
azyang] at [2007-9-26 1:32:56]

hello everybody xerces-2_0_0_beta4 is validating aganist schema here is the code i tested
import java.io.*;
import org.apache.xerces.parsers.SAXParser;
import org.xml.sax.helpers.DefaultHandler;
import org.xml.sax.SAXException;
import org.xml.sax.Attributes;
import org.xml.sax.InputSource;
public class Test extends DefaultHandler
{
public Test()
{
try
{
SAXParser sp = new SAXParser();
sp.setFeature("http://apache.org/xml/features/validation/schema",true);
sp.setFeature("http://xml.org/sax/features/validation",true);
sp.setContentHandler(this);
InputSource is = new InputSource(new FileReader("personal-schema.xml"));
sp.parse(is);
}
catch(SAXException e)
{
System.out.println("Exception While Parsing "+ e);
return;
}
catch(IOException e)
{
System.out.println(e);
return;
}
}
public void startDocument()
{
p("Document Started");
}
public void endDocument()
{
p("Document Ended");
}
public void startElement(String uri,String localName,String qName,Attributes attributes)
{
p("localName" + localName );
}
public void characters(char[] ch, int start, int length)
{
String s1 = new String(ch,start,length);
//p(s1);
}
public void endElement(String uri, String localName, String qName)
{
}
public void p(String s)
{
System.out.println(s);
}
public void p(int s)
{
System.out.println(s);
}
public static void main(String args[])
{
Test t = new Test();
}
}