Hi Werner,
with Version 1.2 your code does not work, but with the unstable version
1.3rc1!
But if the global element is defined by a sequence (0/1 -- unbounded)
#######################################
<xs:element name="oneElement">
<complexType>
<xs:sequence minOccurs="0" maxOccurs="unbounded">
<xs:element name="param" type="ParameterDefinition"/>
</xs:sequence>
</xs:complexType>
</xs:element>
######################################
it is not recogniized as a element definition.
In the descriptor class the field _elementDefinition is set to false,
and the Unmarshaller returns not OneElementXml but OneElementXmlItem.
If I change minOccurs/maxOccurs to 1/1 then _elementDefinition is set to
true and the Unmarshaller returns OnElementXml.
But I have to define a global element as an unbounded sequence, so that
there is no good workaround for this.
Do you have any ideas regarding this strange behaviour?
Thank you
/roman
Werner Guttmann schrieb:
> Hi Roman,
>
> I just got your sample working (against SVN trunk) by changing the code
> to unmarshal things to:
>
> XMLContext context = new XMLContext();
> context.addPackage("your.package");
>
> Unmarshaller unmarshaller = context.createUnmarshaller();
>
> Reader source = new FileReader(exampleXml);
> Object object = unmarshaller.unmarshal(source);
>
> I hope this helps.
>
> Regards
> Werner
>
> Roman Klaehne wrote:
>> Hi Werner,
>>
>>
>> before creating a Jira issue I want to be sure whether I did all correct
>> and that it is really a bug. It is that I need the functionality as soon
>> as possible and I think it will take a quite long time for resolving the
>> issue.
>>
>> For this reason I give you exactly the data of my simple test case,
>> plain in this mail. It would be interesting whether you can reproduce
>> the failure:
>>
>> The data:
>>
>> ########## XML-Schema #####################
>> ###########################################
>> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
>> elementFormDefault="qualified" attributeFormDefault="unqualified">
>> <xs:element name="oneElement">
>> <xs:complexType/>
>> </xs:element>
>> <xs:element name="otherElement">
>> <xs:complexType/>
>> </xs:element>
>> </xs:schema>
>> ########################################
>> ########################################
>>
>> ########## Binding file ################
>> ########################################
>> <?xml version="1.0" encoding="ISO-8859-1"?>
>> <binding defaultBindingType="type">
>> <package>
>> <name>castorgen</name>
>> <namespace></namespace>
>> </package>
>>
>> <elementBinding name="oneElement">
>> <java-class name="OneElementXml"/>
>> </elementBinding>
>> <elementBinding name="otherElement">
>> <java-class name="OtherElementXml"/>
>> </elementBinding>
>> </binding>
>> ########################################
>> ########################################
>>
>> ########## exampleXml ##################
>> ########################################
>> <?xml version="1.0" encoding="ISO-8859-1"?>
>> <oneElement>
>> </oneElement>
>> ########################################
>> ########################################
>>
>> The call to Unmarshaller producing the exception:
>>
>> ########################################
>> ########################################
>> Reader source = new FileReader(exampleXml);
>> Unmarshaller unm = new Unmarshaller();
>> Object o = unm.unmarshal(source);
>> ########################################
>> ########################################
>>
>> The used java libraries are listed below.
>>
>>
>> Best Regards
>> /Roman
>>
>> Werner Guttmann schrieb:
>>> Sorry, Roman, but no attachments to any of the mailing lists, as there's
>>> no guarantee that they arrive at the other end.
>>>
>>> As already suggested, can you please create a new Jira issue and attach
>>> your files ?
>>>
>>> Regards
>>> Werner
>>>
>>> Roman Klaehne wrote:
>>>> Hi Werner,
>>>>
>>>>
>>>> in the attachment you will find a very simple Eclipse project, containing
>>>>
>>>> (i) a simple XML Schema (in xml-schema/)
>>>>
>>>> (ii) a binding file for the schema (in xml-schema/castor-bindings)
>>>>
>>>> (iii) the generated class files (in lib/castorgen.jar)
>>>>
>>>> (iv) a simple class castor.test.Test (in src/)
>>>>
>>>> (v) two xml instances in (xml-instances/)
>>>>
>>>> (vi) an ant build file containing the tasks for generating the java
>>>> sources and for compiling the Test class.
>>>>
>>>> The following libraries has to be on the classpath (see .classpath) and
>>>> are not included in the attached ZIP file:
>>>>
>>>> ant-contrib.jar
>>>> castor-1.2-anttasks.jar
>>>> castor-1.2-codegen.jar
>>>> castor-1.2.jar
>>>> castor-1.2-xml.jar
>>>> castor-1.2-xml-schema.jar
>>>> commons-logging.jar
>>>> serializer.jar
>>>> velocity-dep.jar
>>>> xalan-2.7.0.jar
>>>> xercesImpl.jar
>>>> xml-apis.jar
>>>>
>>>> When running the test class (specifying an xml instance, e.g.,
>>>> xml-instances/oneElement.xml) the following exception occurs:
>>>>
>>>> Exception in thread "main" org.exolab.castor.xml.MarshalException: The
>>>> class for the root element 'oneElement' could not be found.{File: [not
>>>> available]; line: 2; column: 13}
>>>> at
>>>> org.exolab.castor.xml.Unmarshaller.convertSAXExceptionToMarshalException(Unmarshaller.java:761)
>>>> at org.exolab.castor.xml.Unmarshaller.unmarshal(Unmarshaller.java:727)
>>>> at org.exolab.castor.xml.Unmarshaller.unmarshal(Unmarshaller.java:616)
>>>> at castor.test.Test.main(Test.java:23)
>>>> Caused by: org.xml.sax.SAXException: The class for the root element
>>>> 'oneElement' could not be found.
>>>> at
>>>> org.exolab.castor.xml.UnmarshalHandler.startElement(UnmarshalHandler.java:1589)
>>>> .....................
>>>>
>>>> What is going wrong?
>>>>
>>>>
>>>> Best Regards!
>>>> /Roman
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> Werner Guttmann schrieb:
>>>>> Roman,
>>>>>
>>>>> a test case attached to a Jira issue. I don't see a reason why this does
>>>>> not work. Can you as such please create an issue at
>>>>>
>>>>> http://jira.codehaus.org/browse/CASTOR
>>>>>
>>>>> and attach a fully working test case. If you are using Maven, there's an
>>>>> archetype available to assist you with this (as documented at
>>>>> http://castor.org/maven-archetypes.html).
>>>>>
>>>>> Regards
>>>>> Werner
>>>>>
>>>>> Roman Klaehne wrote:
>>>>>> Hi Werner,
>>>>>>
>>>>>>> that should work out of the box.
>>>>>> This sounds good. I also thought that it should work.
>>>>>>
>>>>>>> When you used the XML code generator to
>>>>>>> generate the Java classes from your XML schema, it produced (so-called)
>>>>>>> descriptor classes as well. Did you compile those as well, and are these
>>>>>>> available on your classpath as well ?
>>>>>> Yes, the descriptor classes are generated and all generated classes are
>>>>>> on the classpath.
>>>>>>
>>>>>> As I said the following code works fine:
>>>>>>
>>>>>> ***************************************************
>>>>>> Unmarshaller u = new Unmarshaller(RootXml.class)
>>>>>> Object o = u.unmarshal(reader)
>>>>>> ***************************************************
>>>>>>
>>>>>> But if I instantiate the Unmarshaller without a "root class" argument
>>>>>> (using the empty constructor), the error message
>>>>>>
>>>>>> "The class for the root element 'root' could not be found."
>>>>>>
>>>>>> arises.
>>>>>>
>>>>>> My XML-Schema also have a namespace. I don't know whether this is
>>>>>> important. But my XML sources have a the same namespace of course.
>>>>>>
>>>>>> What more information you need to analyze this matter?
>>>>>>
>>>>>>
>>>>>> All the best
>>>>>> /roman
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>> Regards
>>>>>>> Werner Guttmann
>>>>>>>
>>>>>>> Roman Klaehne wrote:
>>>>>>>> Hi,
>>>>>>>>
>>>>>>>>
>>>>>>>> I am using the Castor Source Code Generator together with Castor
>>>>>>>> Unmarshaller.
>>>>>>>>
>>>>>>>> For the simple XML schema:
>>>>>>>>
>>>>>>>> *******************************************************************
>>>>>>>> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
>>>>>>>> elementFormDefault="qualified" attributeFormDefault="unqualified">
>>>>>>>> <xs:element name="root"/>
>>>>>>>> <xs:element name="element"/>
>>>>>>>> </xs:schema>
>>>>>>>> *******************************************************************
>>>>>>>>
>>>>>>>> I have such a binding file:
>>>>>>>>
>>>>>>>> **************************************************
>>>>>>>> <binding defaultBindingType="type">
>>>>>>>> <elementBinding name="root">
>>>>>>>> <java-class name="RootXml"/>
>>>>>>>> </elementBinding>
>>>>>>>> <elementBinding name="element">
>>>>>>>> <java-class name="ElementXml"/>
>>>>>>>> </elementBinding>
>>>>>>>> </binding>
>>>>>>>> **************************************************
>>>>>>>>
>>>>>>>> After generating the source code for the schema using the binding file
>>>>>>>> above I want to unmarshall XML sources to the repective Java classes.
>>>>>>>>
>>>>>>>> When doing
>>>>>>>>
>>>>>>>> ***************************************************
>>>>>>>> Unmarshaller u = new Unmarshaller(RootXml.class)
>>>>>>>> Object o = u.unmarshal(reader)
>>>>>>>> ***************************************************
>>>>>>>>
>>>>>>>> the object o is correctly unmarshalled and is an instance of class
>>>>>>>> RootXml (as it should be).
>>>>>>>>
>>>>>>>> But when using the default constructor of Unmarshaller (without giving
>>>>>>>> the root class RootXml.class) I get the following error message:
>>>>>>>>
>>>>>>>> "The class for the root element 'root' could not be found."
>>>>>>>>
>>>>>>>> My intention is to have XML documents with root elements "<root>" or
>>>>>>>> "<element>" and when calling Unmarshaller.unmarshal() I don't know the
>>>>>>>> type of the XML source (root or element). That means I want to do the
>>>>>>>> following:
>>>>>>>>
>>>>>>>> ****************************************
>>>>>>>> Unmarshaller u = new Unmarshaller();
>>>>>>>> Object o = u.unmarshal();
>>>>>>>>
>>>>>>>> if(o instanceof RootXml) {
>>>>>>>> doRoot();
>>>>>>>> }
>>>>>>>> else if(o instanceof ElementXml) {
>>>>>>>> doElement();
>>>>>>>> }
>>>>>>>> ****************************************
>>>>>>>>
>>>>>>>> Do you have any ideas to get this working?
>>>>>>>>
>>>>>>>>
>>>>>>>> Thanks in advance and best regards
>>>>>>>> /Roman Klähne
>>>>>>>> (ZIB Berlin)
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> ---------------------------------------------------------------------
>>>>>>>> To unsubscribe from this list, please visit:
>>>>>>>>
>>>>>>>> http://xircles.codehaus.org/manage_email
>>>>>>>>
>>>>>>>>
>>>>>>> ---------------------------------------------------------------------
>>>>>>> To unsubscribe from this list, please visit:
>>>>>>>
>>>>>>> http://xircles.codehaus.org/manage_email
>>>>>>>
>>>>>>>
>>>>>> ---------------------------------------------------------------------
>>>>>> To unsubscribe from this list, please visit:
>>>>>>
>>>>>> http://xircles.codehaus.org/manage_email
>>>>>>
>>>>>>
>>>>> ---------------------------------------------------------------------
>>>>> To unsubscribe from this list, please visit:
>>>>>
>>>>> http://xircles.codehaus.org/manage_email
>>>>>
>>>>>
>>>> ------------------------------------------------------------------------
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe from this list, please visit:
>>>>
>>>> http://xircles.codehaus.org/manage_email
>>> ---------------------------------------------------------------------
>>> To unsubscribe from this list, please visit:
>>>
>>> http://xircles.codehaus.org/manage_email
>>>
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe from this list, please visit:
>>
>> http://xircles.codehaus.org/manage_email
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
> http://xircles.codehaus.org/manage_email
>
>
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email