Hi Brent,

It can be done a few ways.

Normally transient="true" should work, but there was a bug in one or two
of the past releases that also required a transient="true" on the
bind-xml element. Should be fixed by 0.9.4.1.

Here are the ways to do it that are compatible with 0.9.4.1 or greater:

1. use transient="true" 

   This can be done on either the <field> element or the <bind-xml>
element.

   <field name="foo" type="string" transient="true"/>
 
   -or-

   <field name="foo" type="string">
      <bind-xml transient="true"/>
   </field>


   If it's done on the <field> element it will be transient for both JDO
and XML.

2. simply specify a setter without specifying a getter

   This will make it a "write" only field (strange, but it works)

   <field name="foo" set-method="setFoo"/>
 
   If you don't specify a set-method Castor will look automatically for
both
   the setter and getter. If you specify only the set-method Castor will
not
   look for the getter.

--Keith



Brent Hale wrote:
> 
> Hi,
> 
> A newbie question I'm sure...
> 
> I'm trying to marshal my information back out to an XML string and want to
> omit an attribute from the output (the receiving application doesn't handle
> its own schema well).  I tried to do it with a mapping file that looks like
> this (the field responseData is the one I'm trying to omit):
> 
>     <class cst:name="QBXMLMsgsRq" cst:access="shared">
>             <map-to cst:xml="QBXMLMsgsRq"/>
>             <field cst:name="oldMessageSetID" cst:type="java.lang.String">
>                     <bind-xml name="oldMessageSetID" node="attribute"/>
>             </field>
>             <field cst:name="newMessageSetID" cst:type="java.lang.String">
>                     <bind-xml name="newMessageSetID" node="attribute"/>
>             </field>
>             <field cst:name="responseData" transient="true"
> cst:type="types.QBXMLMsgsRqItemResponseDataType">
>                     <bind-xml/>
>             </field>
>             <field cst:name="onError"
> cst:type="types.QBXMLMsgsRqItemOnErrorType" cst:required="true">
>                     <bind-xml name="onError" node="attribute"/>
>             </field>
>     </class>
> 
> I try to do it as follows:
> 
> StringWriter sw = new StringWriter();
> Marshaller m = new Marshaller(sw);
> Mapping mapping = new Mapping();
> mapping.loadMapping("mapping.xml");
> 
> m.setMapping(mapping);
> m.marshal(qbxml, sw);           // where qbxml contains my current information.
> String xml = sw.toString();
> 
> At this point I get the XML string I'd expect except that the attribute
> "responseData" is still there.  Reading the documentation I couldn't tell
> how to omit it.  I tried the empty "bind-xml" with no luck.
> 
> Is there a way to do this using Castor or do I just search in the generated
> string myself and yank it out?
> 
> An alternative would be do somehow remove the attribute from the root
> document.  But even though the attribute is not required according to the
> schema, I can find no way of deleting it from the document.
> 
> Thanks,
> 
> Brent
> 
> -----------------------------------------------------------
> If you wish to unsubscribe from this mailing, send mail to
> [EMAIL PROTECTED] with a subject of:
>         unsubscribe castor-dev

----------------------------------------------------------- 
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
        unsubscribe castor-dev

Reply via email to