Hi Luke, see below (LB>) Laslo
Thank you for your response. I have a couple of follow-up questions based on your message. 1. How do classes (in the package) get associated with "any"? For instance I have two elements Form and Aggregate that I want associated (and Castor to generate based on). How do I do this with "any"? LB> As mentioned in the previous mail the XML elements within an "any" tree LB> will only be unmarshalled to associated classes if they live in the same LB> Java package as the class representing the parent XML element (as far as LB> I remember from some testing I did a while ago). So you could do this by LB> generating classes for "Form" and "Aggregate". LB> E.g. running the following schema through the SourceGenerator should LB> provide you with classes that will accept the following xml and create LB> an array of "Form" and "Aggregate" instances... <?xml version = "1.0" encoding = "UTF-8"?> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" > <xsd:element name="Root"> <xsd:complexType> <xsd:sequence> <xsd:any processContents="lax" minOccurs="1" maxOccurs="unbounded"/> </xsd:sequence> </xsd:complexType> </xsd:element> <xsd:element name="Form" type="xsd:string" /> <xsd:element name="Aggregate" type="xsd:string" /> </xsd:schema> <Root> <Form>Ex1</Form> <Aggregate>Ex2</Aggregate> <Aggregate>Ex3</Aggregate> <Form>Ex4</Form> </Root> LB> e.g. getAnyObject(1) should return an instance of Aggregate (the one with "Ex2" content) 2. Is this a way of modelling inheritence in xsd/Castor generation? LB> I don't think so, but maybe someone from the CASTOR team can comment. Luke Stephens -----Original Message----- From: BEDNARIK,LASLO (HP-Germany,ex1) [mailto:[EMAIL PROTECTED]] Sent: Monday, March 11, 2002 9:54 AM To: [EMAIL PROTECTED] Subject: Re: [castor-dev] Generating Objects from Elements that are just t ags. Hi Luke, sounds like you could use the "any" construct in your schema, for example as follows (the "MessageBody" can have any XML content, in my case as a single tree): <xsd:element name="MessageBody"> <xsd:complexType> <xsd:sequence> <xsd:any processContents="lax" minOccurs="1" maxOccurs="1"/> </xsd:sequence> </xsd:complexType> </xsd:element> Castor will react in one of two ways. If the elements encountered in the "any" have associated Java classes in the same package as the one generated for "MessageBody" it will build up the tree as usual - otherwise it will build a tree of AnyNode instances. You may then just ignore the subtree or use it e.g. as follows (this may be a simple example as it marshalls the piece just after it had been unmarshalled): java.lang.Object content = m.getMessageBody().getAnyObject(0); StringWriter myWriter = new StringWriter(); org.exolab.castor.xml.Marshaller ma = new org.exolab.castor.xml.Marshaller(myWriter); ma.setMarshalAsDocument(false); ma.marshal((org.exolab.castor.types.AnyNode)content); myWriter.close(); xmlBody = myWriter.toString(); The above code assumes you got a tree of AnyNodes. Hope this helps, Laslo ====================================================================== _ _ ___ ___ Laslo Bednarik Tel. {0|49}-7031-468-2025 | || | _ \/ __| Software Engineer Telnet 701-2025 | __ | _/\__ \ Fax {0|49}-7031-468-2207 |_||_|_| |___/ 701-2207 =========== Hewlett-Packard ============ ___ _____ = HP Services IT = |_ _|_ _| = Mail: [EMAIL PROTECTED] = | | | | = http://isoit155.bbn.hp.com/~lbednari = |___| |_| ====================================================================== -----Original Message----- From: Stephens, Luke [mailto:[EMAIL PROTECTED]] Sent: Monday, March 11, 2002 3:17 PM To: [EMAIL PROTECTED] Subject: [castor-dev] Generating Objects from Elements that are just tags. I have a couple of Elements in my schema, that I want to treat as PCData (i.e., they are elements that delimit other xml structures/schemas that are not relevant to me. For instance I want to embed a SOAPRequest in another xml doc, but all I care about is getting the SOAPRequest out of my doc. I don't care about the form or structure of the SOAPRequest). If I create Elements in my schema that have no attributes or other elements, Castor does not generate a class for it. Any ideas? Luke Stephens ----------------------------------------------------------- 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 ----------------------------------------------------------- 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
