xerces-j-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tung Mansfield <mansfi...@orbitcommerce.com>
Subject validation
Date Fri, 04 May 2001 16:36:33 GMT
I was trying out the schema validation feature of xerces 1.3.1, but it does
not work for me. Can somebody tell me what I am doing wrong? Here is my
code:

public class TestXML
{
  public static void main(String[] args) throws Exception
  {
    String fileName = "c:/temp/test.xml";
    FileInputStream stream = new FileInputStream(fileName);
		DOMParser parser = new DOMParser();
		parser.setFeature("http://xml.org/sax/features/validation",
true);
	
parser.setFeature("http://apache.org/xml/features/validation/schema", true);
	
parser.setFeature("http://apache.org/xml/features/validation/dynamic",
true);
		parser.setFeature("http://xml.org/sax/features/namespaces",
true);
		parser.setErrorHandler(new MyErrorHandler());
		errHandler = parser.getErrorHandler();
		parser.parse(new InputSource(stream));
  }
}

class MyErrorHandler implements ErrorHandler
{
	public void error(SAXParseException exception) throws SAXException
  	{
		exception.printStackTrace();
	}

	public void warning(SAXParseException exception) throws SAXException
  	{
		exception.printStackTrace();
	}

	public void fatalError(SAXParseException exception) throws
SAXException
 	 {
		exception.printStackTrace();
	}
}

Here are my xml and schema files:

<Root xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance"
xsi:noNamespaceSchemaLocation='test.xsd'>
	<A/>
	<B/>
	<bad/>
</Root>

<xsd:schema xmlns:xsd="http://www.w3.org/2000/10/XMLSchema"
elementFormDefault="qualified">
	<xsd:element name="Root">
		<xsd:complexType>

		<xsd:sequence>
			<xsd:element name="A"/>
			<xsd:element name="B"/>
		</xsd:sequence>
		</xsd:complexType>

	</xsd:element>
</xsd:schema>

When I validate the XML through XMLSpy, it correctly report the error with
the "bad" element. But Xerces did not report any error.

Thanks for your help.

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org


Mime
View raw message