Hi all,

Iam working on the creation of utility of castor. My application gives the
document object from the external services, which i have to unmarshal them
to java objects. Iam writing a generic method to use for all types of
document objects. Is it possible to unmarshal the document object without
related to class object or class loader or with using generic class object.
Here is my method 

        public static Object unmarshalDom(Document document)
        {
                System.out.println("Started UnMarshalling document....");
                Object object=null;
                try {
                        XMLClassDescriptorResolver classDescriptorResolver =
(XMLClassDescriptorResolver)
ClassDescriptorResolverFactory.createClassDescriptorResolver(BindingType.XML);
                        classDescriptorResolver.setInternalContext(new
org.castor.xml.BackwardCompatibilityContext());
                        classDescriptorResolver.setUseIntrospection(true);
                        Class firstnode=(document.getNodeName()).getClass();
                        System.out.println("first node class name"+firstnode);
                        classDescriptorResolver.addClass(firstnode);
                        Unmarshaller unmarshaller = null;
                        unmarshaller = new Unmarshaller();
                        unmarshaller.setResolver(classDescriptorResolver);
                        unmarshaller.setValidation(false);
                        String xmlstring = convertDOMToString(document);
                        StringReader src=new StringReader(xmlstring);
                        object = (Object) unmarshaller.unmarshal(src);
                } catch (Exception e) {
                        System.out.println(e);
                        e.printStackTrace();
                }
                System.out.println("End of UnMarshal document....");
                return object;
        }


and the following is the exception im getting when unmarshalling:
Started UnMarshalling document....
first node class nameclass java.lang.String
org.exolab.castor.xml.MarshalException: The class for the root element


Can you please provide any solution if possible


Thanks for help
Harinath
-- 
View this message in context: 
http://www.nabble.com/Is-castor-can-unmarshal-marshal-the-DOM-object-to-java-object-tp23502151p23502151.html
Sent from the Castor - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply via email to