Modifying XmlBeans document without XmlValueDisconnectedException?

"Lott, Christopher M" <[email protected]> Mon, 19 Aug 2013 21:33:03 +0000
Newsgroups gmane.text.xml.xmlbeans.user
Message-ID <[email protected]>
I tried asking this on StackOverflow, but then realized that this email lis=
t is probably the better place, so please forgive if you read both places. =
 I hope someone can please find time to answer.

We use XmlBeans, code generated from a schema, to read in an XML instance t=
hat conforms to the schema and modify it.  Read and validate work fine; mod=
ify is killing me.  For example, change the value of an element, delete an =
element from a list, etc.  I am using Java method calls like removeMyElemen=
t(i) to remove the element at position (i).  I am not using Cursors or any =
low-level DOM access.

We thought it would be convenient to walk thru the document, gather a list =
of elements (i.e., references to XmlBeans objects) that need to be modified=
 or nuked, then iterate over the list changing them.  But use of a cached o=
bject reference is where I run into the ditch: I get XmlValueDisconnectedEx=
ception.  I read that this means the XmlObject has become disconnected from=
 its underlying store. But I have not discarded the Document!

Does every change to an XmlObject backed by the XmlBeans XmlStore cause all=
 existing references to become invalid?  I don't yet have the right mental =
model for what's going on when I call the java methods.

I checked the XmlBeans FAQ and the sample code for guidelines.  I found man=
y samples at http://xmlbeans.apache.org/samples/ that show how to create an=
 object from scratch, how to read in XML, how to validate XML, etc.  Unfort=
unately I didn't find a sample that does a messy change to the content. The=
 FAQ at http://wiki.apache.org/xmlbeans/XmlBeansFaq doesn't have a good que=
stion on this either.

Thanks in advance.=