I have used Castor to generate code for the marshalling framework based on an xml schema. I want to use the default marshalling behavoir except for one attribute in one element. So I created a mapping for the class and set the auto-complete attribute to true, then specified a field mapping for that attribute. I would expect that when I marshalled the object that it would use the default behavoir for all fields except for the one I specified a mapping for, in which case the mapping would override that behavior. Instead, when I marshalled the object I got _both_ behaviors (two attributes appeared in the xml - one with the attribute name I specified with bind-xml,the other with the default attribute name - both had the same value.
Here's the relevant portion of the scheme:
...
<xs:element name="tuv">
<xs:complexType>
...
<xs:attribute name="xml:lang" type="xs:string" use="required"/>
</xs:complexType>
</xs:element>
...
The class is generated with the following:
public class Tuv implements java.io.Serializable {
private java.lang.String _lang;
...
public java.lang.String getLang()
{
return this._lang;
} //-- java.lang.String getLang()
public void setLang(java.lang.String lang)
{
this._lang = lang;
} //-- void setLang(java.lang.String)
...
So I specify the following mapping:
<mapping>
<class name="com.dcx.i18n.xml.Tuv" auto-complete="true">
<field name="lang" required="true">
<bind-xml name="xml:lang" node="attribute"/>
</field>
</class>
</mapping>
I then create a Tuv object, set the _lang property and marshall:
...
Tuv tuv = new Tuv();
tuv.setLang("EN");
Writer wr = new BufferedWriter(new FileWriter(_path));
Mapping mapping = new Mapping();
URL url = ClassLoader.getSystemResource(mappingFile);
mapping.loadMapping(url);
Marshaller marshaller = new Marshaller(wr);
marshaller.setMapping(mapping);
marshaller.marshal(tuv);
...
What I get is the following:
...
<tuv xml:lang="EN" lang="EN"></tuv>
...
I would expect:
...
<tuv xml:lang="EN"></tuv>
...
Any thoughts? I'm out of ideas here.
--
Joe Banks
_________________________________________________________________
Help STOP SPAM with the new MSN 8 and get 2 months FREE* http://join.msn.com/?page=features/junkmail
----------------------------------------------------------- If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
unsubscribe castor-dev
