Reinhard, can you please make sure that the (generated) .castor.xml file is included with your (compiled) code as well. Are you using Ant ? Or Maven ? In eitehr case, you will have to find a way to put that file into your classpath.
Regards Werner Reinhard Weiss wrote: > hi, > > i have generated class files using the castor 1.2 code generator. so in my > project there are the packages > > com.xyz.model [containing the .castor.cdr] and > com.xyz.model.descriptors > > > > i have used a custom binding to bind the actual xml document element <A> to > class B.java. > > <?xml version="1.0" encoding="UTF-8"?> > <binding xmlns="http://www.castor.org/SourceGenerator/Binding" > xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" > xsi:schemaLocation="http://www.castor.org/SourceGenerator/Binding > http://castor.org/binding.xsd" defaultBindingType="element"> > <package> > <name>com.xyz.model</name> > <namespace>http://www.xyz.com/</namespace> > </package> > <elementBinding name="/A"> > <java-class name="B"/> > </elementBinding> > </binding> > > > > the xml schema is: > > <?xml version="1.0" encoding="UTF-8"?> > <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" > xmlns:ns1="http://www.xyz.com/" targetNamespace="http://www.xyz.com/" > elementFormDefault="qualified" attributeFormDefault="unqualified"> > <xs:element name="A"> > <xs:complexType> > <xs:sequence> > <xs:element name="text" type="xs:string"/> > </xs:sequence> > </xs:complexType> > </xs:element> > </xs:schema> > > > > when i invoke the unmarshal(org.w3c.dom.Node) method on an unmarshaller > instance, i keep getting the following exception... > > org.exolab.castor.xml.MarshalException: The class for the root element 'A' > could not be found. > at > org.exolab.castor.xml.Unmarshaller.convertSAXExceptionToMarshalException(Unmarshaller.java:761) > at org.exolab.castor.xml.Unmarshaller.unmarshal(Unmarshaller.java:640) > at org.exolab.castor.xml.Unmarshaller.unmarshal(Unmarshaller.java:747) > > > > ... although i have configured the xmlcontext like > > XMLContext context = new XMLContext(); > context.addPackage("com.xyz.model"); > context.setProperty(XMLConfiguration.LOAD_PACKAGE_MAPPING, true); > context.setProperty(XMLConfiguration.NAMESPACE_PACKAGE_MAPPINGS, > "http://www.xyz.com/=com.xyz.model"); > > > > the testcase looks like: > > public void testUnmarshalNode() throws Exception > { > XMLContext context = new XMLContext(); > context.addPackage("com.xyz.model"); > context.setProperty(XMLConfiguration.LOAD_PACKAGE_MAPPING, true); > context.setProperty(XMLConfiguration.NAMESPACE_PACKAGE_MAPPINGS, > "http://www.xyz.com/=com.xyz.model"); > Unmarshaller unmarshaller = context.createUnmarshaller(); > > String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><a:A > xmlns:a=\"http://www.xyz.com/\"><a:text>hello world</a:text></a:A>"; > > DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); > DocumentBuilder builder = factory.newDocumentBuilder(); > InputSource is = new InputSource( new StringReader( xml ) ); > Document xmlDocument = builder.parse( is ); > > B b = (B) unmarshaller.unmarshal(xmlDocument); // <- fails > > assertNotNull(b); > assertEquals("hello world", b.getText()); > } > > > > for some reason castor doesn't consider the classdescriptor on unmarshalling > [at least that's what seems to be the problem]. > how can i properly setup my unmarshaller/xmlcontext to get things right? > > thanks, > > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > > DI Reinhard Weiss > > ANECON Software Design und Beratung G.m.b.H. > > Web: http://www.anecon.com > > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > > Zusätzliche Pflichtangaben von Kapitalgesellschaften gem. § 14 UGB: > FN166941b | Handelsgericht Wien | Firmensitz Wien > > > > > ------------------------------------------------------------------------ > > --------------------------------------------------------------------- > To unsubscribe from this list, please visit: > > http://xircles.codehaus.org/manage_email --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email

