- From: Mark Proctor <mproctor@codehaus.org>
- Date: Mon, 25 Oct 2004 14:52:19 +0200
- To: George Cristian Bina <george@sync.ro>
- CC: xmlschema-dev@w3.org
I've resolved the issue. I returned to my original code and property, turns out its the array order - rules.xsd must be in the array before the other .xsds, is that a bug? Thanks for your patience and help Mark Mark Proctor wrote: > > I just tried it doing getResource and toExternalForm which produces > the following string: > jar:file:/D:/java/workspaces/drools/target/drools-java-2.0-beta-18.jar!/META-INF/java.xsd > jar:file:/D:/java/workspaces/drools/target/drools-python-2.0-beta-18.jar!/META-INF/python.xsd > jar:file:/D:/java/workspaces/drools/target/drools-groovy-2.0-beta-18.jar!/META-INF/groovy.xsd > jar:file:/D:/java/workspaces/drools/target/drools-base-2.0-beta-18.jar!/META-INF/rules.xsd > > > I do this using the following code: > URL java = cl.getResource( "META-INF/java.xsd" ); > URL python = cl.getResource( "META-INF/python.xsd" ); > URL groovy = cl.getResource( "META-INF/groovy.xsd" ); > URL rules = cl.getResource( "META-INF/rules.xsd" ); > String url = ""; > > if ( java != null ) url = url + java.toExternalForm() + " "; > if ( python != null ) url = url + python.toExternalForm() + " "; > if ( groovy != null ) url = url + groovy.toExternalForm() + " "; > if ( rules != null ) url = url + rules.toExternalForm(); > > parser.setProperty( JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA ); > parser.setProperty("http://apache.org/xml/properties/schema/external-schemaLocation", > url); > > But now I get the following error, like its not finding the xsds at all: > (jar:file:/D:/java/workspaces/drools/drools-examples/target/drools-examples-2.0-beta-18.jar!/org/drools/examples/fibonacci/fibonacci.java.drl:5,57) > : cvc-elt.1: Cannot find the declaration of element 'rule-set'. > > Mark > Mark Proctor wrote: > >> I currently use: >> private static final String JAXP_SCHEMA_LANGUAGE = >> "http://java.sun.com/xml/jaxp/properties/schemaLanguage"; >> private static final String W3C_XML_SCHEMA = >> "http://www.w3.org/2001/XMLSchema"; >> private static final String SCHEMA_SOURCE = >> "http://java.sun.com/xml/jaxp/properties/schemaSource"; >> As detailed in the following IBM article: >> http://www-106.ibm.com/developerworks/xml/library/x-tipvalschm/ >> I do know that our original xsds worked with that property, but that >> was where we imported the java namespace into rules.xsd and used choice. >> >> I'm looking at xerces and see that it has its own properties as well. >> http://xml.apache.org/xerces-j/properties.html >> However using this property I can no longer specify the xsds as an >> InputStream, how would I specify urls for files that are in jars, >> which themselves are in the classpath? >> >> Regards >> >> Mark >> George Cristian Bina wrote: >> >>> Hi Mark, >>> >>> Well, the following schemas plus instance are valid(Xerces 2.6.2). I >>> do not know what SCHEMA_SOURCE contains in your code line: >>> >>> parser.setProperty(SCHEMA_SOURCE,( InputStream[] ) >>> schemaList.toArray( new InputStream[0] ) ); >>> >>> You may try setting a value similar with the one from schemaLocation >>> attribute to the >>> http://apache.org/xml/properties/schema/external-schemaLocation >>> property. >>> >>> rules.xsd >>> ========= >>> >>> <?xml version="1.0" encoding="UTF-8"?> >>> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" >>> targetNamespace="http://drools.org/rules" >>> elementFormDefault="qualified" >>> xmlns:rules="http://drools.org/rules"> >>> <xs:element name="rule-set"> >>> <xs:complexType> >>> <xs:sequence> >>> <xs:element minOccurs="0" maxOccurs="unbounded" >>> ref="rules:rule"/> >>> </xs:sequence> >>> <xs:attribute name="name" use="required" type="xs:string"/> >>> <xs:attribute name="description" type="xs:string"/> >>> </xs:complexType> >>> </xs:element> >>> <xs:element name="rule"> >>> <xs:complexType> >>> <xs:sequence> >>> <xs:element name="parameter" maxOccurs="unbounded"> >>> <xs:complexType> >>> <xs:sequence> >>> <xs:element ref="rules:class"/> >>> </xs:sequence> >>> <xs:attribute name="identifier" >>> use="required" type="xs:string"/> >>> </xs:complexType> >>> </xs:element> >>> <xs:element ref="rules:condition" >>> maxOccurs="unbounded"/> >>> <xs:element ref="rules:consequence"/> >>> </xs:sequence> >>> <xs:attribute name="name" use="required" type="xs:string"/> >>> <xs:attribute name="salience" type="xs:integer"/> >>> <xs:attribute name="no-loop" type="xs:boolean"/> >>> <xs:attribute name="description" type="xs:string"/> >>> </xs:complexType> >>> </xs:element> >>> <xs:element name="class" type="xs:string" abstract="true"/> >>> <xs:element name="condition" type="xs:string" abstract="true"/> >>> <xs:element name="consequence" type="xs:string" abstract="true"/> >>> </xs:schema> >>> >>> java.xsd >>> ======== >>> >>> <?xml version="1.0" encoding="UTF-8"?> >>> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" >>> targetNamespace="http://drools.org/semantics/java" >>> elementFormDefault="qualified" >>> xmlns:java="http://drools.org/semantics/java" >>> xmlns:rules="http://drools.org/rules"> >>> <xs:import namespace="http://drools.org/rules" >>> schemaLocation="rules.xsd"/> >>> <xs:element name="class" type="xs:string" >>> substitutionGroup="rules:class"/> >>> <xs:element name="condition" type="xs:string" >>> substitutionGroup="rules:condition"/> >>> <xs:element name="consequence" type="xs:string" >>> substitutionGroup="rules:consequence"/> >>> </xs:schema> >>> >>> sample.xml >>> ========== >>> >>> <?xml version="1.0" encoding="UTF-8"?> >>> <rule-set name="fibonacci" xmlns="http://drools.org/rules" >>> xmlns:java="http://drools.org/semantics/java" >>> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >>> xsi:schemaLocation="http://drools.org/semantics/java java.xsd >>> http://drools.org/rules rules.xsd"> >>> <rule name="Recurse" salience="10"> >>> <parameter identifier="f"> >>> >>> <java:class>org.drools.examples.fibonacci.Fibonacci</java:class> >>> </parameter> >>> <java:condition>f.getValue() == -1</java:condition> >>> <java:consequence> System.err.println( "recurse for " + >>> f.getSequence() ); >>> drools.assertObject( new Fibonacci( f.getSequence() - 1 >>> ) ); </java:consequence> >>> </rule> >>> </rule-set> >>> >>> Best Regards, >>> George >>> --------------------------------------------------------------------- >>> George Cristian Bina >>> <oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger >>> http://www.oxygenxml.com >>> >>> >> >> > > > >
Received on Monday, 25 October 2004 12:52:53 UTC