I think the ContentHandler suggestion will be the most efficient since the XML will only get parsed once. But if you really don't want to use that approach, another approach similar to Stephen's XQuery suggestion would be to use an XSLT stylesheet to pre-process your XML. It won't be as efficient as the ContentHandler, but it should suffice.

Another approach would be to use a custom field handler and simply drop the items you don't want. While it won't prevent Castor from loading the objects, it will prevent them from being added to the collection. You could even get creative in the FieldHandler's newInstance() method to return cached values that you want to re-use:

private static ObjectCache cachedObject = new ObjectCache();

public void setValue(Object target, Object value) {

   if (isGood(value)) {
      ((MyParent).addObject(value);
   }
   else {
      clearValues(value);
      cachedObject.put(value);
   }
}

public Object newInstance( Object parent ) {
   Object obj = cachedObject.get();
   if (obj == null) {
      return new MyObjectType();
   }
}

HTH,

--Keith

Stephen Bash wrote:
Rob-

It probably isn't too helpful, but my first reaction would be to use
an XQuery processor to slice up the XML file and then unmarshal the
result in Castor.  You might look into the listener interfaces in
Castor (I'm thinking UnmarshalListener), but I don't think those offer
any control, just event notification.  Another option is to create a
ContentHandler that sits between the parser and Castor that only sends
Castor the events that you want it to receive.  There might be an
easier way to do this, but those are the off-the-top-of-my-head
solutions...

If you get a solution that works, please let us know, as it will
probably help others in the future.

Stephen


On 3/28/06, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:

Hi,

I'm unmarshalling an xml in which there can be multiple instances of the
same node-type. Within each node is an identifying string that tells me to
what the information contained in the node pertains. I only need information
from one node with a particular identifying string. Is there any way to
check that string prior to the unmarshalling? In other words, I want to
avoid unmarshalling all the nodes into a collection of objects and looking
for the specific string by iterating through the collection. I'd rather
check before the unmarshalling so I only  one object (that corresponds to
that node) gets instantiated.

Any ideas?

Thanks,
Rob

-----------------------------------------
Robert Lerner
Senior Consultant
Vichara Technologies, Inc
646-344-3541

________________________________






*******************************************************************
****
This E-mail is confidential. It may also be legally privileged. If
you
are not the addressee you may not copy, forward, disclose or use
any
part of it. If you have received this message in error, please
delete
it and all copies from your system and notify the sender
immediately
by return E-mail.

Internet communications cannot be guaranteed to be timely, secure,
error or virus-free. The sender does not accept liability for any
errors or omissions.
*******************************************************************
****






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

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

Reply via email to