Hi all, i've started working with XML Schema support in the datatype package.
Here are some proposals for improvement : (I'm not a Java-Pro, so my workarounds are q & d !) The SchemaParser class doesn't handle includes of other schemata. ------------------------------------ As a workaround, i added the following lines to SchemaParser.java: private static final QName XSD_INCLUDE = QName.get("include", XSD_NAMESPACE); /** Parses the given schema document * * @param schemaDocument is the document of the XML Schema */ public void build( Document schemaDocument ) { Element root = schemaDocument.getRootElement(); if ( root != null ) { //handle schema includes Iterator includeIter = root.elementIterator( XSD_INCLUDE); while (includeIter.hasNext()) { Element includeElement = (Element) includeIter.next(); String inclSchemaInstanceURI = includeElement.attributeValue("schemaLocation"); EntityResolver resolver = schemaDocument.getEntityResolver(); try { if ( resolver == null ) { throw new InvalidSchemaException( "No EntityResolver available so could not resolve the schema URI: " + inclSchemaInstanceURI ); } InputSource inputSource = resolver.resolveEntity( null, inclSchemaInstanceURI ); if ( inputSource == null ) { throw new InvalidSchemaException( "Could not resolve the schema URI: " + inclSchemaInstanceURI ); } SAXReader reader = new SAXReader(); Document inclSchemaDocument = reader.read( inputSource ); build( inclSchemaDocument ); } catch (Exception e) { System.out.println( "Failed to load schema: " + inclSchemaInstanceURI ); System.out.println( "Caught: " + e ); e.printStackTrace(); throw new InvalidSchemaException( "Failed to load schema: " + inclSchemaInstanceURI ); } } //handle elements .... Missing support of element types, derived from simpleType: --------------------------------------------------------------------------------- // Implementation methods //------------------------------------------------------------------------- /** processes an XML Schema <element> tag */ protected void onDatatypeElement( Element xsdElement , DocumentFactory parentFactory ) { String name = xsdElement.attributeValue( "name" ); String type = xsdElement.attributeValue( "type" ); QName qname = getQName( name ); DatatypeElementFactory elementFactory = getDatatypeElementFactory( qname ); if ( type != null ) { // register type with this element name XSDatatype dataType = getTypeByName(type); if (dataType!=null) { elementFactory.setChildElementXSDatatype( qname, dataType ); } else { QName typeQName=getQName(type); namedTypeResolver.registerTypedElement(xsdElement,typeQName,parentFactory); } return; } // handle element types derrived from simpleTypes Element xsdSimpleType = xsdElement.element( XSD_SIMPLETYPE ); if ( xsdSimpleType != null ) { System.out.println("Agfa-sg: handle element types derrived from simpleTypes for element: " + name); XSDatatype dataType = loadXSDatatypeFromSimpleType( xsdSimpleType ); if (dataType != null) { System.out.println("dataType (from loadXSDatatypeFromSimpleType) = " + dataType); elementFactory.setChildElementXSDatatype( qname, dataType ); } } Element schemaComplexType = xsdElement.element( XSD_COMPLEXTYPE ); ..... Greetings Stefan Graeber _______________________________________________ dom4j-dev mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/dom4j-dev