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]
# 1

The W3C only chose a schema proprosal in the last few months so the parser probably won't come out for a little while. The accepted proposal is available at http://www.w3.org/2001/XMLSchema it contains a XML Schema DTD as well as a XML Schema Schema (don't think about the metaphysics of this too much or your head might implode.)

dubwai at 2007-6-29 1:34:44 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 2
hello: Yestday,I downloaded a parser that surports Shema.You can download it at the wedsite: http://xml.apache.org/dist/xerces-j/Xerces-J-src.1.2.2.zip. if you want,send Email to me(liu8421@263.net).
horseliu at 2007-6-29 1:34:44 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 3
Send me an e-mail (duncan.groenewald@txu.com.au) if you are still looking for sample program and sample XML Schema docs.
duncangroenewald at 2007-6-29 1:34:44 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 4

The version of Xerces that you are using does not yet support XML Schema. It only supports DTD validation. It is so because the XML Schema recommendation has not yet been finalized at the time Xerces 1.4.1 was written. The version that supports it is Xerces version 1.4.4 and Xerces version 2 beta 3. Alternatively , you can try MultiSchema Validator from Sun at http://www.sun.com.

Hope this helps

khmerr at 2007-6-29 1:34:44 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 5

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();

}

}

rohith1122 at 2007-6-29 1:34:44 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...