Oliver,
That's the thing, changeType does change the schema type assigned to that node and returns a new java object of a different class but it doesn't change the structure of the document. What you're looking for can be done programmatically since all the info is available in the schema types but to make it work correctly for all the type is no easy job. Cezar _____ From: Oliver Pfau [mailto:oliver.p...@scalaris.com] Sent: Tuesday, November 17, 2009 3:55 AM To: user@xmlbeans.apache.org Subject: AW: changeType to type with fewer element Hi Cezar, imagine the following: a complex type "Top" is existing and an inherited complex type "Sub" from "Top" is existing. Sub does extend Top with a string value "Something". If I do the following: Top topsub = Top.Factory.newInstance(); topsub.changeType(Sub.type); topsub.setSomething("a value only for sub"); topsub.changeType(Top.type)); boolean isValid = topsub.validate(); isValid will be false, because topsub is at the end of type Top but the xml output defines the something element of sub. My expectation is that the changeType(Top.type) will cause that the something element will be ignored and not unmarshalled to xml and validation. Regards, Oliver _____ Von: Cezar Andrei [mailto:cezar.and...@oracle.com] Gesendet: Montag, 16. November 2009 21:45 An: user@xmlbeans.apache.org Betreff: RE: changeType to type with fewer element Oliver, I'm not sure what is your question, but you have to keep in mind that validation is run only when validate() method is invoked. Especially when it is structure related operations modifying the document don't keep the document valid. Most of the time a document has to go through a series of invalid states to become valid again. XMLBeans' user cooperation is required to attain document's validity after modifications. Cezar _____ From: Oliver Pfau [mailto:oliver.p...@scalaris.com] Sent: Friday, November 13, 2009 7:03 AM To: user@xmlbeans.apache.org Subject: changeType to type with fewer element Hi, it seems that XmlBeans is generating invalid xml when I change the type to a type with fewer elements. There is an example with abstract conrete types on the XmlBeans homepage called "AbstractTypes". In the file AbstractTypes.java there is this section: ... Circle circle = (Circle) s1.changeType(Circle.type); circle.setRadius(10.0); ... s1 is a shape (more common). If the type of circle is changed to a more common type, the radius is nevertheless set for the Shape type. The Validation of the changed circle to a Shape will fail, because the radius is existing in the xml event though the xsi:type is correct. The xml and the java representation seems to be here out of sync. Isn't it ? Or is there a trick ? Regards, Oliver