You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-dev@xerces.apache.org by bu...@apache.org on 2002/10/08 21:33:15 UTC

DO NOT REPLY [Bug 13420] New: - Complex Validation not catching error

DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=13420>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=13420

Complex Validation not catching error

           Summary: Complex Validation not catching error
           Product: Xerces2-J
           Version: 2.1.0
          Platform: PC
        OS/Version: Windows NT/2K
            Status: NEW
          Severity: Critical
          Priority: Other
         Component: DOM
        AssignedTo: xerces-j-dev@xml.apache.org
        ReportedBy: bhszekel@us.ibm.com


JAVA LISTING (A)
----------------
import org.w3c.dom.*;
import org.apache.xerces.parsers.*;
import org.xml.sax.InputSource;
import java.io.*;
import org.xml.sax.ErrorHandler;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;

public class Validate implements ErrorHandler {

	public static void main(String[] args) throws Exception {
		try {
			InputSource src = new InputSource(new FileInputStream
("envelope.xml"));
			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);
			String schemas = "urn:xml-soap-address-demo address.xsd 
http://schemas.xmlsoap.org/soap/envelope/ 
http://schemas.xmlsoap.org/soap/envelope/";
			parser.setProperty
("http://apache.org/xml/properties/schema/external-schemaLocation",schemas);
			parser.setErrorHandler(new Validate());
			parser.parse(src);
			Document doc = parser.getDocument();
			Node root = doc.getDocumentElement();
			System.out.println("ROOT: " + root.getNodeName());
		} catch (Exception e) {
			System.out.println("Exc: " + e.getMessage());
			e.printStackTrace();
		}
	}

	public void error(SAXParseException e) throws SAXException {
		System.out.println("ERROR: " + e.getMessage());
	}

	public void fatalError(SAXParseException e) throws SAXException {
		System.out.println("FATAL ERROR: " + e.getMessage());
	}

	public void warning(SAXParseException e) throws SAXException {
		System.out.println("WARNING: " + e.getMessage());
	}

}

INSTANCE DOCUMENT (B) envelope.xml
---------------------
<?xml version='1.0' encoding='UTF-8'?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
				   xmlns:xsi="http://www.w3.org/2001/XMLSchema-
instance"
				   xmlns:xsd="http://www.w3.org/2001/XMLSchema">
	<SOAP-ENV:Body>
		<ns1:addEntry xmlns:ns1="urn:AddressFetcher" SOAP-
ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
			<nameToRegister 
xsi:type="xsd:string">Ben</nameToRegister>
			<xaddress xmlns:ns2="urn:xml-soap-address-demo" 
xsi:type="ns2:address">
				<city xsi:type="xsd:string">Cambridge</city>
				<phoneNumber xsi:type="ns2:phone">
					<areaCode 
xsi:type="xsd:int">607</areaCode>
					<exchange 
xsi:type="xsd:string">339</exchange>
					<number 
xsi:type="xsd:string">1540</number>
				</phoneNumber>
				<state xsi:type="xsd:string">MA</state>
				<streetName 
xsi:type="xsd:string">JFK</streetName>
				<streetNum xsi:type="xsd:int">50</streetNum>
				<zip xsi:type="xsd:int">2138</zip>
			</xaddress>
		</ns1:addEntry>
	</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

XML SCHEMA (C) address.xsd
--------------

<xsd:schema targetNamespace="urn:xml-soap-address-demo" xmlns:tns="urn:xml-soap-
address-demo" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
	<xsd:complexType name="address">
		<xsd:all>
			<xsd:element name="city" type="xsd:string"/>
			<xsd:element name="phoneNumber" type="tns:phone"/>
			<xsd:element name="state" type="xsd:string"/>
			<xsd:element name="streetName" type="xsd:string"/>
			<xsd:element name="streetNum" type="xsd:int"/>
			<xsd:element name="zips" type="xsd:int"/>
		</xsd:all>
	</xsd:complexType>
	<xsd:complexType name="phone">
		<xsd:all>
			<xsd:element name="areaCode" type="xsd:int"/>
			<xsd:element name="exchange" type="xsd:string"/>
			<xsd:element name="number" type="xsd:string"/>
		</xsd:all>
	</xsd:complexType>
</xsd:schema>

BUG DESCRIPTION
---------------

When I run the java code in (A), no validation errors are reported on instance 
document (B).  However, notice that the schema document specifies "zips" and 
the instance document has element <zip>.  When I turn off the dynamic 
validation feature, the proper validation error is reported.  So for some 
reason, the dynamic validation is ignoring part of a complex type even though a 
grammar exists for that type.  If this is not a bug, please advise.  Thanks you.

       Ben Szekely
  IBM Internet Technologies

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