The Address has it's own type and is imported into the main schema via another schema. I did as you said: BusinessDescription.Contact contact = businessDescription.addNewContact(); contact.setAddress(address); contact.xmlText() or businessDescription.getContact().xmlText() gives <rol:BS7666Address xmlns:rol="http://www.rol.co.uk" <http://www.rol.co.uk> ><bs7:AdministrativeArea xmlns:bs7="http://www.govtalk.gov.uk/people/bs7666" <http://www.govtalk.gov.uk/people/bs7666> >TEST</bs7:AdministrativeArea></rol:BS7666Address>
However for: BusinessDescription.Contact contact = BusinessDescription.Contact.Factory.newInstance(); businessDescription.setContact(contact); contact.setAddress(address); contact.xmlText() gives <rol:BS7666Address xmlns:rol="http://www.rol.co.uk" <http://www.rol.co.uk> ><bs7:AdministrativeArea xmlns:bs7="http://www.govtalk.gov.uk/people/bs7666" <http://www.govtalk.gov.uk/people/bs7666%22%3ETEST%3C/bs7:AdministrativeArea %3E%3C/rol:BS7666Address> >TEST</bs7:AdministrativeArea></rol:BS7666Address> However, businessDescription.getContact().xmlText() gives <xml-fragment/> I have seen the same behaviour with DateTime. I was doing: contact.setDateTime(Calendar.getInstance()) // line 1 contact.getDateTime().setTime(someDate); // line 2 If I call contact.getDateTime() now it will still hold the same date and time set in line 1 I had to change the code to do: Calendar cal = Calendar.getInstance(); cal.setTime(someDate); contact.setDateTime(someDate); I assumed this must be due to XMLBeans passing back a copy of the Calendar object when calling contact.getDateTime() _____ From: Jacob Danner [mailto:[EMAIL PROTECTED] Sent: 11 January 2008 17:52 To: [email protected] Subject: Re: [newbie] difference between addNew and (Factory.newInstance + set) Hi Paul, Can you do a System.out.println(contact.xmlText()); in each of the scenarios below? How is Address defined in the schema? Thanks, -jacobd On Jan 11, 2008 9:29 AM, Paul French < [EMAIL PROTECTED]> wrote: Hello, I have created a library using scomp from an xml schema. I am building a XML document using this library. I have come across some behaviour I do not understand. For this example a BusinessDescription may have a Contact and a Contact may have an Address. If I do the following: BusinessDescription.Contact contact = businessDescription.addNewContact(); contact.setAddress(address); if (businessDescription.getContact().getAddress() != null) { System.out.println("Address is not null"); } else { System.out.println("Address is null"); } My code prints out "Address is not null" as expected However If I do the following: BusinessDescription.Contact contact = BusinessDescription.Contact.Factory.newInstance(); businessDescription.setContact(contact); contact.setAddress(address); if (businessDescription.getContact().getAddress() != null) { System.out.println("Address is not null"); } else { System.out.println("Address is null"); } My code prints out "Address is null". For some reason setting the address on the contact object after the contact object is set on the businessDescription is ignored. XMLBeans must be cloning objects internally?? This behaviour is unintuitive to me? Can someone explain. Thanks -- I'm competing in a Half-Ironman distance triathlon to raise money for the fight against cancer! Please help support my efforts by going to: http://www.active.com/donate/tntwaak/jacobd

