I've convinced myself that this is a bug, and I'm hoping that somebody on the 
dev list might help me figure out what's going on.  I'm very new to Castor and 
even newer to the internals of Castor, so I'm hoping somebody might be willing 
to give me some pointers, work with me to fix this issue, or maybe just help me 
find a workaround.

When I originally posted this issue, I assumed it was my misuse of Castor (and 
it still could very well be), but I've continued to dig into the problem, and I 
now believe it is a bug.  Here are some sample XML docs to demonstrate:

Working:
1) <xead>   <y>a</y>   <z>b</z>   </xead>
2) <xead> 1 <y>a</y>   <z>b</z>   </xead>
3) <xead>   <y>a</y>   <z>b</z> 3 </xead>
4) <xead> 1 <y>a</y>   <z>b</z> 3 </xead>

Failing:
5) <xead>   <y>a</y> 2 <z>b</z>   </xead>
6) <xead> 1 <y>a</y> 2 <z>b</z>   </xead>
7) <xead>   <y>a</y> 2 <z>b</z> 3 </xead>
8) <xead> 1 <y>a</y> 2 <z>b</z> 3 </xead> 


I ran each of these through a simple unmarshalling routine (see below).  This 
routine used Java objects that were created by Castor's source generator and 
the following XSD:

<xs:schema
        xmlns:xs="http://www.w3.org/2001/XMLSchema"; 
        elementFormDefault="qualified"
        targetNamespace="http://dlib.indiana.edu/";
        xmlns:ns1="http://dlib.indiana.edu/";
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";>

        <xs:element name="xead">
                <xs:complexType mixed="true">
                        <xs:choice minOccurs="0" maxOccurs="unbounded">
                                <xs:element ref="ns1:y" />
                                <xs:element ref="ns1:z" />
                        </xs:choice>
                </xs:complexType>
        </xs:element>

        <xs:element name="y" type="xs:NCName"/>
        <xs:element name="z" type="xs:NCName"/>

</xs:schema>


Every one of the failed XML docs produce a log output of:
[Castor] #startElement: xead
[Castor] #characters:  1 
[Castor] #startElement: y
[Castor] #container: _items
[Castor] #characters: a
[Castor] #endElement: y
[Castor] #characters:  2 
[Castor] #startElement: z
[Castor] #endElement: _items

And a stack dump similar to the one shown in the original posting below.

I should note, I'm using Castor 0.9.9.1.

It looks to me like there should be some additional checking at 
org.exolab.castor.xml.UnmarshalHandler.startElement(UnmarshalHandler.java:835) 
to see if character content is allowed, but instead it just tosses out an 
exception.  But I'm just starting to get into the code, so that's probably a 
pretty naïve statement...


So I've searched through Jira, and found a couple of bugs that look related:
* http://jira.codehaus.org/browse/CASTOR-513
* http://jira.codehaus.org/browse/CASTOR-498

But the comments indicate there is possibly a fix available?  It's not totally 
clear to me what the actual status is, or if it's even the same bug.


Lastly, if I switch the xs:choice to a xs:sequence, it unmarshalls, but the 
order of the <y> and <z> is lost in the generated code (not to mention that my 
real XML wouldn't validate by doing this).  Looking at it from this angle made 
me question if Castor will correctly recreate the text contents when 
marshalling test cases 4, 6, 7, and 8.  I'm thinking not based on bug #513...


So, back to my original point in posting: Is there anybody out there who would 
be willing to help me get started on fixing this issue (or finding a 
workaround)?  I'm very happy to dig into the code and do what I can do, but I 
have very little experience with Castor internals.  And that's assuming it is 
actually a bug.  If not, I'd love to hear what is wrong with my thinking! :)


Thanks!
        -Eric.


> -----Original Message-----
> From: Peters, Eric James 
> Sent: Tuesday, December 20, 2005 1:44 PM
> To: '[email protected]'
> Subject: Unmarshalling error
> 
> 
> I've been dealing with a problem with Castor, and I think 
> I've finally simplified it to the point that I understand it 
> well enough to ask a question...  Well, maybe understand is 
> too overstated, I can at least point in the general right direction :)
> 
> Anyway, I have a drastically simplified XML doc, and used 
> oXygen to generate a valid schema.  I then ran Castor's 
> source generator to create the Java classes, and wrote some 
> simple code to unmarshall the XML doc into Java objects.  
> However, I am getting an exception that doesn't make any sense to me.
> 
> Here are the details:
> 
> * I have a drastically simplified XML doc: 
> 
> <xead xmlns="http://dlib.indiana.edu/";
>     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
>     xsi:schemaLocation="http://dlib.indiana.edu/ xead.xsd">
>     <xcreation>
>         data<xlb/>more data<xdate>October 19, 1998</xdate>
>     </xcreation>
> </xead>
> 
> 
> * I used oXygen to generate a valid schema:
> 
> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"; 
> elementFormDefault="qualified" 
> targetNamespace="http://dlib.indiana.edu/"; 
> xmlns:ns1="http://dlib.indiana.edu/"; 
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";>
>   <xs:element name="xead">
>     <xs:complexType>
>       <xs:sequence>
>         <xs:element ref="ns1:xcreation"/>
>       </xs:sequence>
>     </xs:complexType>
>   </xs:element>
>   <xs:element name="xcreation">
>     <xs:complexType mixed="true">
>       <xs:choice minOccurs="0" maxOccurs="unbounded">
>         <xs:element ref="ns1:xdate"/>
>         <xs:element ref="ns1:xlb"/>
>       </xs:choice>
>     </xs:complexType>
>   </xs:element>
>   <xs:element name="xdate" type="xs:string"/>
>   <xs:element name="xlb">
>     <xs:complexType/>
>   </xs:element>
> </xs:schema>
> 
> 
> * I ran Castor's source generator to create the Java classes:
> 
> C:\...\>java org.exolab.castor.builder.SourceGenerator -dest 
> ..\..\..\.. -package edu.indiana.dlib.metadata.xead -types j2 
> -i xead.xsd -verbose
> 
> Creating classes for: xlb
> Creating classes for: xead
> Creating classes for: xcreation
> 
> Output classes available on request...  I also used 
> -gen-mapping, but there was no file created (even though the 
> source generator stated "generating mapping file: xeadmap.xml").
> 
> 
> * I wrote some simple code to unmarshall the XML doc into 
> Java objects:
> 
> ...
> Reader r = new FileReader(filename);
> PrintWriter l = Logger.getSystemLogger();
> Unmarshaller u = new Unmarshaller(Xead.class);
> u.setLogWriter(l); 
> u.setDebug(true);
> return (Xead)u.unmarshal(r);
> 
> 
> * I am getting an exception:
> 
> [Castor] #startElement: xead
> [Castor] #characters: 
> [Castor]     
> [Castor] #startElement: xcreation
> [Castor] #characters: 
> [Castor]         data
> [Castor] #startElement: xlb
> [Castor] #container: _items
> [Castor] #endElement: xlb
> [Castor] #characters: more data
> [Castor] #startElement: xdate
> [Castor] #endElement: _items
> edu.indiana.dlib.metadata.xead.XEadGenerationException: 
> Illegal Text data found as child of: _items
>   value: "more data"{file: [not available]; line: 6; column: 35}
>       at 
> edu.indiana.dlib.metadata.xead.XEadUtil.GenerateRawXEad(XEadUt
> il.java:46)
>       at 
> edu.indiana.dlib.metadata.xead.XEadUtil.GenerateXEad(XEadUtil.java:18)
>       at 
> edu.indiana.dlib.infrastructure.CastorXEADTest.main(CastorXEAD
> Test.java:15)
> Caused by: Illegal Text data found as child of: _items
>   value: "more data"{file: [not available]; line: 6; column: 35}
>       at 
> org.exolab.castor.xml.Unmarshaller.unmarshal(Unmarshaller.java:671)
>       at 
> org.exolab.castor.xml.Unmarshaller.unmarshal(Unmarshaller.java:565)
>       at 
> edu.indiana.dlib.metadata.xead.XEadUtil.GenerateRawXEad(XEadUt
> il.java:42)
>       ... 2 more
> Caused by: org.xml.sax.SAXException: Illegal Text data found 
> as child of: _items
>   value: "more data"
>       at 
> org.exolab.castor.xml.UnmarshalHandler.endElement(UnmarshalHan
> dler.java:889)
>       at 
> org.exolab.castor.xml.UnmarshalHandler.startElement(UnmarshalH
> andler.java:1720)
>       at 
> org.exolab.castor.xml.UnmarshalHandler.startElement(UnmarshalH
> andler.java:1381)
>       at 
> org.apache.xerces.parsers.AbstractSAXParser.startElement(Unkno
> wn Source)
>       at 
> org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanStar
> tElement(Unknown Source)
>       at 
> org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$Fragment
> ContentDispatcher.dispatch(Unknown Source)
>       at 
> org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocu
> ment(Unknown Source)
>       at 
> org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
>       at 
> org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
>       at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
>       at 
> org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
>       at 
> org.exolab.castor.xml.Unmarshaller.unmarshal(Unmarshaller.java:657)
>       ... 4 more
> 
> 
> What am I doing wrong here?
> 
> Thanks!
>       -Eric.
> 
> 

-------------------------------------------------
If you wish to unsubscribe from this list, please
send an empty message to the following address:

[EMAIL PROTECTED]
-------------------------------------------------

Reply via email to