You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xerces.apache.org by Ka...@silverline.com on 2002/06/26 04:18:17 UTC

Problem with XML Schema resource location in default handler

Hi,
I have been using XML schema for validating XML documents in one of our applications and i've been using the xercer java parser 2.0.1

It seems to be doing its job well if i specify the following in the instance document..

<TESTDATA xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:noNamespaceSchemaLocation="c:\jakarta-tomcat-4.0.3\webapps\struts-upload\testdata.xsd">
...
</TESTDATA>



But i've been trying to specifiy the property for locating the schema in a class that implements the default handler,

<TESTDATA xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

...

</TESTDATA>

code snippet:

String EXTERNAL_SCHEMA_NONAMESPACE_LOCATION_PROPERTY_ID = "http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation";

	XMLReader xr = XMLReaderFactory.createXMLReader();
	
	//set the following properties
            xr.setProperty(EXTERNAL_SCHEMA_NONAMESPACE_LOCATION_PROPERTY_ID,"c:\jakarta-tomcat-4.0.3\webapps\struts-upload\testdata.xsd");


	//set the following features
            xr.setFeature(NAMESPACES_FEATURE_ID, true);            
            xr.setFeature(NAMESPACE_PREFIXES_FEATURE_ID, true);           
            xr.setFeature(SCHEMA_FULL_CHECKING_FEATURE_ID, true); 
            xr.setFeature(VALIDATION_FEATURE_ID, true);
            xr.setFeature(SCHEMA_VALIDATION_FEATURE_ID, true);                  
            xr.setFeature(DYNAMIC_VALIDATION_FEATURE_ID, true);
	xr.parse( new InputSource(fileInputStream) ); //pass the XML file input stream

The event handler class just parses the XML file.. and the rules specified in the schema are not validated. 

I also tried with "http://apache.org/xml/properties/schema/external-schemaLocation"; and provided a URI before the XSD file while setting the property, but no luck 

Could any one please let me know if i'm missing anything.. 
Would appreciate a ton...

- Kalyan