Why don't I get exception when invalid XML is validated with Schema?

weiliossy

New Member
Here is XML Schema:\[code\]<?xml version="1.0" encoding="utf-8"?><xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="products"> <xs:complexType> <xs:sequence minOccurs="0" maxOccurs="unbounded"> <xs:element name="product" type="ProductType"/> </xs:sequence> </xs:complexType> </xs:element> <xs:complexType name="ProductType"> <xs:sequence> <xs:element name="id" type="xs:long" /> <xs:element name="name" type="xs:string" /> <xs:element name="price" type="xs:decimal" /> </xs:sequence> </xs:complexType></xs:schema>\[/code\]XML file that is validated for conformance:\[code\]<?xml version="1.0" ?><products> <product> <invalid_tag>32342</invalid_tag> <name>Some name</name> <price>3.89</price> </product></products>\[/code\]Java code that works with XML and should test conformance:\[code\]SAXParserFactory factory = SAXParserFactory.newInstance();factory.setValidating(false);SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);factory.setSchema(schemaFactory.newSchema(new File(xmlSchema)));parser = factory.newSAXParser();ProductsSaxHandler handler = new ProductsSaxHandler();parser.parse(new File(xmlFile), handler);\[/code\]But I don't get any exception. What is wrong?
 
Back
Top