Re: Add to XmlBeans FAQ re orphaned objects and XmlValueDisconnectedException

Cezar Andrei <[email protected]> Wed, 21 Aug 2013 10:02:55 -0700 (PDT)
Newsgroups gmane.text.xml.xmlbeans.user
Message-ID <1377104575.4512.1.camel@i7>
I added the new question and answer to the Faq page.

XmlObject.copy() should be much more efficient than toString() and
parse().

Cezar

On Tue, 2013-08-20 at 07:10 -0700, Lott, Christopher M wrote:
> I would like to suggest an addition to page http://wiki.apache.org/xmlbeans/XmlBeansFaq but I cannot edit it, so am trying the email list.   Please redirect me if I'm sending this to the wrong place. 
> 
> Is this Q & A sufficient and clear?  Thanks for listening.
> 
> 
> Q: Why am I getting XmlValueDisconnectedException when I try to change an XmlObject?
> 
> A: The most likely cause is that the XmlObject is an orphan; i.e., it has become disassociated from the XML store.  This can happen if you get a reference to an object (perhaps by fetching the first item in an array), delete the item from the tree (perhaps by calling the array remove method on element 0), and then try to invoke methods on that reference or any of its child elements.  You cannot even invoke the toString() method on an orphaned object!  If you need to keep a deleted object, make a copy before you delete it. For example:
> 
>               LineItem nl = LineItem.Factory.parse(p.getLineItemArray(0).toString());
>               p.removeLineItem(0);
> 
> 
> Credit this to Paul Gillen and also the people who posted to a thread in 2006:
> 
> http://mail-archives.apache.org/mod_mbox/xmlbeans-user/200602.mbox/%[email protected]%3E
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>