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