Hi Pedro,

Castor doesn't have any built-in support for filtering at this time.

You could create a custom FieldHandler to do the filtering for you, and
specify this in a mapping file, if you have the desire to do so...

<mapping>
<!-- The below mapping modifies the ListTypeDescriptor
     generted for the class ListType, the auto-complete
     attribute is set to true so that castor will
     use the remaining fields from ListTypeDescriptor. -->
<class name="com.acme.ListType" auto-complete="true">

   <!-- the name of the field must match exactly the name 
        specified in the ListTypeDescriptor -->
       
   <field name="_element" type="com.acme.ElementType"
collection="vector"
       handler="com.acme.ListFilterHandler"/>

</class>

</mapping>

The ListFilterHandler would be your custom FieldHandler (which must
implement FieldHandler (or extend GeneralizedFieldHandler)) and provide
your filtering based on the name.

It would return in the getValue() method, an enumeration containing only
the items that you wanted to marshal.

Then just make sure you only use this mapping file for marshalling, and
not unmarshalling.

Hope that helps,

--Keith

Pedro Salazar wrote:
> 
> Greetings,
> 
> I have a XML file with N elements child of a root element (list).
> I would like to marshalling to a java object instance just the element
> child with the key name "XX" instead marshalling all the elements on the
> XML file. Can castor do it?
> 
> For example, I have a XML file with lots of entries "elements" but only
> one of them is required in a certain moment. If my XML file is
> considerable big, I will loose several time marshalling objects that I
> won't need.
> 
> <list>
>         <element name="1" />
>         <element name="2" />
>         <element name="3" />
>         <element name="4" />
>         ...
>         <element name="N" />
> </list>
> 
> <!----- SCHEMA ------>
> 
> <xs:element name="list" type="listType">
>         <xs:key name="element">
>             <xs:selector xpath="element"/>
>             <xs:field xpath="@name"/>
>         </xs:key>
> </xs:element>
> <xs:element name="element" type="med:elementType"/>
> 
> <xs:complexType name="listType">
>         <xs:sequence>
>             <xs:element ref="list" minOccurs="0" maxOccurs="unbounded"/>
>         </xs:sequence>
> </xs:complexType>
> 
> <xs:complexType name="elementType">
>         <xs:attribute name="name" type="xs:string"/>
> </xs:complexType>
> 
> thanks,
> Pedro Salazar.
> --
> PS
> pedro-b-salazar_at_ptinovacao_dot_pt
> PGP:0E129E31D803BC61
> 
> -----------------------------------------------------------
> 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