I'm using subtitution groups to allow a configuration file to have a list of different configuration elements. If I strip down the schema to the attached schema (Ce and Be form a substitution group) and generate the code, when I attempt to unmarshal something like
<De xmlns="http://www.csiro.org/castorprob"> <Be/> </De> then all is OK. However, attempting to unmarshal something like <De xmlns="http://www.csiro.org/castorprob"> <Be/> <Ce/> </De> causes the exception: Element with name Ce passed to type De in incorrect order; It is not allowed to be the last element of this sequence!{File: [not available]; line: 4; column: 8} Attached is a schema, ant build file, code and test cases to reproduce this behavior. Put the .xsd/.xml files is an "xml" subdirectory, Test.java in a src/org/csiro/castorprob subdirectory and add the castor, commons-logging and xercesImpl jars to the lib subdirectory. Then do "ant run" to reproduce the results.
castor-bindings.xml
Description: application/xml
test.xsd
Description: application/xml
test1.xml
Description: application/xml
test2.xml
Description: application/xml
test3.xml
Description: application/xml
test4.xml
Description: application/xml
build.xml
Description: application/xml
package org.csiro.castorprob;
import java.io.*;
import java.net.*;
import org.exolab.castor.xml.*;
import org.exolab.castor.xml.util.XMLClassDescriptorResolverImpl;
/**
* Test reading an XML document.
*
* @author Doug Palmer
*
*/
public class Test {
private XMLClassDescriptorResolverImpl resolver;
public Test() throws ResolverException {
this.resolver = new XMLClassDescriptorResolverImpl();
this.resolver.addClass(Be.class.getName());
this.resolver.addClass(Ce.class.getName());
this.resolver.addClass(De.class.getName());
}
public Object read(URL url) throws IOException, ValidationException, MarshalException {
Reader reader = new InputStreamReader(url.openStream());
Unmarshaller unmarshaller = new Unmarshaller();
unmarshaller.setResolver(this.resolver);
return unmarshaller.unmarshal(reader);
}
public static void main(String[] args) {
try {
Test test = new Test();
for (String arg: args) {
try {
URL file = new URL(arg);
System.out.println(test.read(file));
} catch (Exception ex) {
ex.printStackTrace(System.err);
}
}
} catch (Exception ex) {
ex.printStackTrace(System.err);
}
}
}
---------------------------------------------------------------------
To unsubscribe from this list please visit:
http://xircles.codehaus.org/manage_email

