RE: Modifying XmlBeans document without XmlValueDisconnectedException?
"Paul Gillen" <[email protected]> Mon, 19 Aug 2013 22:17:07 -0400
| Newsgroups | gmane.text.xml.xmlbeans.user |
|---|---|
| Message-ID | <[email protected]> |
------=_NextPart_000_00CD_01CE9D29.D822EAB0
Content-Type: text/plain;
charset="us-ascii"
Content-Transfer-Encoding: 7bit
If I understand you correctly you are trying to print something you removed;
it gone baby. If for some reason you need it, preserve a copy, not a
reference.
package org.eltesto;
import java.io.File;
import java.math.BigDecimal;
import java.math.BigInteger;
import org.openuri.easypo.LineItem;
import org.openuri.easypo.PurchaseOrderDocument;
import org.openuri.easypo.PurchaseOrderDocument.PurchaseOrder;
public class Main {
public static void main(String[] args) throws Exception {
Main m = new Main();
m.go(args);
}
private void go(String[] args) throws Exception {
File f = new File("easypo.xml");
PurchaseOrderDocument pd =
PurchaseOrderDocument.Factory.parse(f);
System.out.println("ORIGINAL\n"+pd.xmlText());
PurchaseOrder p = pd.getPurchaseOrder();
LineItem l = p.addNewLineItem();
l.setDescription("foo");
l.setPerUnitOunces(new BigDecimal("1"));
l.setPrice(new BigDecimal("2"));
l.setQuantity(new BigInteger("3"));
System.out.println("\nLINE ITEM ADDED\n"+pd.xmlText());
LineItem nl =
LineItem.Factory.parse(p.getLineItemArray(0).toString());
p.removeLineItem(0);
System.out.println("\nLINE ITEM DELETED\n"+pd.xmlText());
System.out.println("\nCOPY OF DELETED LINE
ITEM\n"+nl.xmlText());
}
}
Output:
ORIGINAL
<purchase-order xmlns="http://openuri.org/easypo">
<customer>
<name>Gladys Kravitz</name>
<address>Anytown, PA</address>
</customer>
<date>2003-01-07T14:16:00-05:00</date>
<line-item>
<description>Burnham's Celestial Handbook, Vol 1</description>
<per-unit-ounces>5</per-unit-ounces>
<price>21.79</price>
<quantity>2</quantity>
</line-item>
<line-item>
<description>Burnham's Celestial Handbook, Vol 2</description>
<per-unit-ounces>5</per-unit-ounces>
<price>19.89</price>
<quantity>2</quantity>
</line-item>
<shipper>
<name>ZipShip</name>
<per-ounce-rate>0.74</per-ounce-rate>
</shipper>
</purchase-order>
LINE ITEM ADDED
<purchase-order xmlns="http://openuri.org/easypo">
<customer>
<name>Gladys Kravitz</name>
<address>Anytown, PA</address>
</customer>
<date>2003-01-07T14:16:00-05:00</date>
<line-item>
<description>Burnham's Celestial Handbook, Vol 1</description>
<per-unit-ounces>5</per-unit-ounces>
<price>21.79</price>
<quantity>2</quantity>
</line-item>
<line-item>
<description>Burnham's Celestial Handbook, Vol 2</description>
<per-unit-ounces>5</per-unit-ounces>
<price>19.89</price>
<quantity>2</quantity>
</line-item>
<line-item><description>foo</description><per-unit-ounces>1</per-unit-ounces
><price>2</price><quantity>3</quantity></line-item><shipper>
<name>ZipShip</name>
<per-ounce-rate>0.74</per-ounce-rate>
</shipper>
</purchase-order>
LINE ITEM DELETED
<purchase-order xmlns="http://openuri.org/easypo">
<customer>
<name>Gladys Kravitz</name>
<address>Anytown, PA</address>
</customer>
<date>2003-01-07T14:16:00-05:00</date>
<line-item>
<description>Burnham's Celestial Handbook, Vol 2</description>
<per-unit-ounces>5</per-unit-ounces>
<price>19.89</price>
<quantity>2</quantity>
</line-item>
<line-item><description>foo</description><per-unit-ounces>1</per-unit-ounces
><price>2</price><quantity>3</quantity></line-item><shipper>
<name>ZipShip</name>
<per-ounce-rate>0.74</per-ounce-rate>
</shipper>
</purchase-order>
COPY OF DELETED LINE ITEM
<xml-fragment xmlns:eas="http://openuri.org/easypo">
<eas:description>Burnham's Celestial Handbook, Vol 1</eas:description>
<eas:per-unit-ounces>5</eas:per-unit-ounces>
<eas:price>21.79</eas:price>
<eas:quantity>2</eas:quantity>
</xml-fragment>
On the other hand I might be completely FOS. Please let me know if this is
the case.
Cordially,
Paul Gillen
-----Original Message-----
From: Lott, Christopher M [mailto:[email protected]]
Sent: Monday, August 19, 2013 9:33 PM
To: <[email protected]>
Subject: Re: Modifying XmlBeans document without
XmlValueDisconnectedException?
Thanks to Nick B. and Paul G. for their quick replies! Below is code that
demonstrates, at least superficially, the exception that we get. We are
doing something wrong in our code; I don't suspect an XmlBeans bug at this
point. This code is derived from (and depends on the schema and example XML
instance from) the XmlBeans tutorial at
<http://xmlbeans.apache.org/documentation/tutorial_getstarted.html>
http://xmlbeans.apache.org/documentation/tutorial_getstarted.html
--
package my.xb.example;
import java.io.File;
import java.math.BigDecimal;
import java.math.BigInteger;
import org.openuri.easypo.LineItem;
import org.openuri.easypo.PurchaseOrderDocument;
public class POUpdater {
public static void main(String[] args) throws Exception {
if (args.length < 5)
throw new Exception("Usage:
inputfile desc ounces price quantity");
File poXmlFile = new File(args[0]);
String updatedPoXml = addLineItem(poXmlFile,
args[1], args[2], args[3],
args[4]);
System.out.println(updatedPoXml);
}
private static String addLineItem(File purchaseOrder,
String itemDescription,
String perUnitOuncesString,
String itemPriceString,
String itemQuantityString) throws Exception {
// Read in the file content
PurchaseOrderDocument poDoc =
PurchaseOrderDocument.Factory
.parse(purchaseOrder);
// Convert incoming data to types that can
be used in accessors.
BigDecimal perUnitOunces = new
BigDecimal(perUnitOuncesString);
BigDecimal itemPrice = new
BigDecimal(itemPriceString);
BigInteger itemQuantity = new
BigInteger(itemQuantityString);
// Add a new <line-item> element.
LineItem newItem =
poDoc.getPurchaseOrder().addNewLineItem();
newItem.setDescription(itemDescription);
newItem.setPerUnitOunces(perUnitOunces);
newItem.setPrice(itemPrice);
newItem.setQuantity(itemQuantity);
// Delete the old first line item
LineItem removedItem =
poDoc.getPurchaseOrder().getLineItemArray(0);
poDoc.getPurchaseOrder().removeLineItem(0);
// Try to access the newly added one; is the
ref still good?
System.out.println("new item: " +
newItem.toString());
newItem.setDescription(newItem.getDescription() + " fu");
// Try to access the removed one; this
throws XmlValueDisconnectedException
System.out.println("removed item: " +
removedItem.toString());
return poDoc.toString();
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: <mailto:[email protected]>
[email protected]
For additional commands, e-mail: <mailto:[email protected]>
[email protected]
------=_NextPart_000_00CD_01CE9D29.D822EAB0
Content-Type: text/html;
charset="us-ascii"
Content-Transfer-Encoding: quoted-printable
<html xmlns:v=3D"urn:schemas-microsoft-com:vml" =
xmlns:o=3D"urn:schemas-microsoft-com:office:office" =
xmlns:w=3D"urn:schemas-microsoft-com:office:word" =
xmlns:m=3D"http://schemas.microsoft.com/office/2004/12/omml" =
xmlns=3D"http://www.w3.org/TR/REC-html40"><head><meta =
http-equiv=3DContent-Type content=3D"text/html; =
charset=3Dus-ascii"><meta name=3DGenerator content=3D"Microsoft Word 14 =
(filtered medium)"><style><!--
/* Font Definitions */
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Calibri","sans-serif";}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:purple;
text-decoration:underline;}
p.MsoPlainText, li.MsoPlainText, div.MsoPlainText
{mso-style-priority:99;
mso-style-link:"Plain Text Char";
margin:0in;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Calibri","sans-serif";}
span.PlainTextChar
{mso-style-name:"Plain Text Char";
mso-style-priority:99;
mso-style-link:"Plain Text";
font-family:"Calibri","sans-serif";}
.MsoChpDefault
{mso-style-type:export-only;}
@page WordSection1
{size:8.5in 11.0in;
margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext=3D"edit" spidmax=3D"1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext=3D"edit">
<o:idmap v:ext=3D"edit" data=3D"1" />
</o:shapelayout></xml><![endif]--></head><body lang=3DEN-US link=3Dblue =
vlink=3Dpurple><div class=3DWordSection1><p class=3DMsoPlainText>If I =
understand you correctly you are trying to print something you removed; =
it gone baby. If for some reason you need it, preserve a copy, not =
a reference.<o:p></o:p></p><p =
class=3DMsoPlainText><o:p> </o:p></p><p class=3DMsoPlainText =
style=3D'margin-left:.5in'><span =
style=3D'font-size:8.0pt;font-family:"Courier New"'>package =
org.eltesto;<o:p></o:p></span></p><p class=3DMsoPlainText =
style=3D'margin-left:.5in'><span =
style=3D'font-size:8.0pt;font-family:"Courier =
New"'><o:p> </o:p></span></p><p class=3DMsoPlainText =
style=3D'margin-left:.5in'><span =
style=3D'font-size:8.0pt;font-family:"Courier New"'>import =
java.io.File;<o:p></o:p></span></p><p class=3DMsoPlainText =
style=3D'margin-left:.5in'><span =
style=3D'font-size:8.0pt;font-family:"Courier New"'>import =
java.math.BigDecimal;<o:p></o:p></span></p><p class=3DMsoPlainText =
style=3D'margin-left:.5in'><span =
style=3D'font-size:8.0pt;font-family:"Courier New"'>import =
java.math.BigInteger;<o:p></o:p></span></p><p class=3DMsoPlainText =
style=3D'margin-left:.5in'><span =
style=3D'font-size:8.0pt;font-family:"Courier =
New"'><o:p> </o:p></span></p><p class=3DMsoPlainText =
style=3D'margin-left:.5in'><span =
style=3D'font-size:8.0pt;font-family:"Courier New"'>import =
org.openuri.easypo.LineItem;<o:p></o:p></span></p><p =
class=3DMsoPlainText style=3D'margin-left:.5in'><span =
style=3D'font-size:8.0pt;font-family:"Courier New"'>import =
org.openuri.easypo.PurchaseOrderDocument;<o:p></o:p></span></p><p =
class=3DMsoPlainText style=3D'margin-left:.5in'><span =
style=3D'font-size:8.0pt;font-family:"Courier New"'>import =
org.openuri.easypo.PurchaseOrderDocument.PurchaseOrder;<o:p></o:p></span>=
</p><p class=3DMsoPlainText style=3D'margin-left:.5in'><span =
style=3D'font-size:8.0pt;font-family:"Courier =
New"'><o:p> </o:p></span></p><p class=3DMsoPlainText =
style=3D'margin-left:.5in'><span =
style=3D'font-size:8.0pt;font-family:"Courier New"'>public class Main =
{<o:p></o:p></span></p><p class=3DMsoPlainText =
style=3D'margin-left:.5in'><span =
style=3D'font-size:8.0pt;font-family:"Courier =
New"'> public static void =
main(String[] args) throws Exception {<o:p></o:p></span></p><p =
class=3DMsoPlainText style=3D'margin-left:.5in'><span =
style=3D'font-size:8.0pt;font-family:"Courier =
New"'> &=
nbsp; Main m =3D new Main();<o:p></o:p></span></p><p =
class=3DMsoPlainText style=3D'margin-left:.5in'><span =
style=3D'font-size:8.0pt;font-family:"Courier =
New"'> &=
nbsp; m.go(args);<o:p></o:p></span></p><p class=3DMsoPlainText =
style=3D'margin-left:.5in'><span =
style=3D'font-size:8.0pt;font-family:"Courier =
New"'> }<o:p></o:p></span></p><p =
class=3DMsoPlainText style=3D'margin-left:.5in'><span =
style=3D'font-size:8.0pt;font-family:"Courier =
New"'> private void go(String[] =
args) throws Exception {<o:p></o:p></span></p><p class=3DMsoPlainText =
style=3D'margin-left:.5in'><span =
style=3D'font-size:8.0pt;font-family:"Courier =
New"'> &=
nbsp; File f =3D new =
File("easypo.xml");<o:p></o:p></span></p><p =
class=3DMsoPlainText style=3D'margin-left:.5in'><span =
style=3D'font-size:8.0pt;font-family:"Courier =
New"'> &=
nbsp; PurchaseOrderDocument pd =3D =
PurchaseOrderDocument.Factory.parse(f);<o:p></o:p></span></p><p =
class=3DMsoPlainText style=3D'margin-left:.5in'><span =
style=3D'font-size:8.0pt;font-family:"Courier =
New"'> &=
nbsp; =
System.out.println("ORIGINAL\n"+pd.xmlText());<o:p></o:p></span=
></p><p class=3DMsoPlainText style=3D'margin-left:.5in'><span =
style=3D'font-size:8.0pt;font-family:"Courier =
New"'> &=
nbsp; <o:p></o:p></span></p><p class=3DMsoPlainText =
style=3D'margin-left:.5in'><span =
style=3D'font-size:8.0pt;font-family:"Courier =
New"'> &=
nbsp; PurchaseOrder p =3D =
pd.getPurchaseOrder();<o:p></o:p></span></p><p class=3DMsoPlainText =
style=3D'margin-left:.5in'><span =
style=3D'font-size:8.0pt;font-family:"Courier =
New"'> &=
nbsp; <o:p></o:p></span></p><p class=3DMsoPlainText =
style=3D'margin-left:.5in'><span =
style=3D'font-size:8.0pt;font-family:"Courier =
New"'> &=
nbsp; LineItem l =3D p.addNewLineItem();<o:p></o:p></span></p><p =
class=3DMsoPlainText style=3D'margin-left:.5in'><span =
style=3D'font-size:8.0pt;font-family:"Courier =
New"'> &=
nbsp; l.setDescription("foo");<o:p></o:p></span></p><p =
class=3DMsoPlainText style=3D'margin-left:.5in'><span =
style=3D'font-size:8.0pt;font-family:"Courier =
New"'> &=
nbsp; l.setPerUnitOunces(new =
BigDecimal("1"));<o:p></o:p></span></p><p class=3DMsoPlainText =
style=3D'margin-left:.5in'><span =
style=3D'font-size:8.0pt;font-family:"Courier =
New"'> &=
nbsp; l.setPrice(new =
BigDecimal("2"));<o:p></o:p></span></p><p class=3DMsoPlainText =
style=3D'margin-left:.5in'><span =
style=3D'font-size:8.0pt;font-family:"Courier =
New"'> &=
nbsp; l.setQuantity(new =
BigInteger("3"));<o:p></o:p></span></p><p class=3DMsoPlainText =
style=3D'margin-left:.5in'><span =
style=3D'font-size:8.0pt;font-family:"Courier =
New"'> &=
nbsp; System.out.println("\nLINE ITEM =
ADDED\n"+pd.xmlText());<o:p></o:p></span></p><p =
class=3DMsoPlainText style=3D'margin-left:.5in'><span =
style=3D'font-size:8.0pt;font-family:"Courier =
New"'> &=
nbsp; <o:p></o:p></span></p><p class=3DMsoPlainText =
style=3D'margin-left:.5in'><span =
style=3D'font-size:8.0pt;font-family:"Courier =
New"'> &=
nbsp; LineItem nl =3D =
LineItem.Factory.parse(p.getLineItemArray(0).toString());<o:p></o:p></spa=
n></p><p class=3DMsoPlainText style=3D'margin-left:.5in'><span =
style=3D'font-size:8.0pt;font-family:"Courier =
New"'> &=
nbsp; <o:p></o:p></span></p><p class=3DMsoPlainText =
style=3D'margin-left:.5in'><span =
style=3D'font-size:8.0pt;font-family:"Courier =
New"'> &=
nbsp; p.removeLineItem(0);<o:p></o:p></span></p><p =
class=3DMsoPlainText style=3D'margin-left:.5in'><span =
style=3D'font-size:8.0pt;font-family:"Courier =
New"'> &=
nbsp; System.out.println("\nLINE ITEM =
DELETED\n"+pd.xmlText());<o:p></o:p></span></p><p =
class=3DMsoPlainText style=3D'margin-left:.5in'><span =
style=3D'font-size:8.0pt;font-family:"Courier =
New"'> &=
nbsp; <o:p></o:p></span></p><p class=3DMsoPlainText =
style=3D'margin-left:.5in'><span =
style=3D'font-size:8.0pt;font-family:"Courier =
New"'> &=
nbsp; System.out.println("\nCOPY OF DELETED LINE =
ITEM\n"+nl.xmlText());<o:p></o:p></span></p><p class=3DMsoPlainText =
style=3D'margin-left:.5in'><span =
style=3D'font-size:8.0pt;font-family:"Courier =
New"'> }<o:p></o:p></span></p><p =
class=3DMsoPlainText style=3D'margin-left:.5in'><span =
style=3D'font-size:8.0pt;font-family:"Courier =
New"'>}<o:p></o:p></span></p><p =
class=3DMsoPlainText><o:p> </o:p></p><p =
class=3DMsoPlainText>Output:<o:p></o:p></p><p class=3DMsoPlainText =
style=3D'margin-left:.5in'><span =
style=3D'font-size:8.0pt;font-family:"Courier =
New"'>ORIGINAL<o:p></o:p></span></p><p class=3DMsoPlainText =
style=3D'margin-left:.5in'><span =
style=3D'font-size:8.0pt;font-family:"Courier New"'><purchase-order =
xmlns=3D"http://openuri.org/easypo"><o:p></o:p></span></p><p=
class=3DMsoPlainText style=3D'margin-left:.5in'><span =
style=3D'font-size:8.0pt;font-family:"Courier New"'> =
<customer><o:p></o:p></span></p><p class=3DMsoPlainText =
style=3D'margin-left:.5in'><span =
style=3D'font-size:8.0pt;font-family:"Courier =
New"'> <name>Gladys =
Kravitz</name><o:p></o:p></span></p><p class=3DMsoPlainText =
style=3D'margin-left:.5in'><span =
style=3D'font-size:8.0pt;font-family:"Courier =
New"'> <address>Anytown, =
PA</address><o:p></o:p></span></p><p class=3DMsoPlainText =
style=3D'margin-left:.5in'><span =
style=3D'font-size:8.0pt;font-family:"Courier New"'> =
</customer><o:p></o:p></span></p><p class=3DMsoPlainText =
style=3D'margin-left:.5in'><span =
style=3D'font-size:8.0pt;font-family:"Courier New"'> =
<date>2003-01-07T14:16:00-05:00</date><o:p></o:p></span></p><=
p class=3DMsoPlainText style=3D'margin-left:.5in'><span =
style=3D'font-size:8.0pt;font-family:"Courier New"'> =
<line-item><o:p></o:p></span></p><p class=3DMsoPlainText =
style=3D'margin-left:.5in'><span =
style=3D'font-size:8.0pt;font-family:"Courier =
New"'> =
<description>Burnham's Celestial Handbook, Vol =
1</description><o:p></o:p></span></p><p class=3DMsoPlainText =
style=3D'margin-left:.5in'><span =
style=3D'font-size:8.0pt;font-family:"Courier =
New"'> =
<per-unit-ounces>5</per-unit-ounces><o:p></o:p></span></p><p =
class=3DMsoPlainText style=3D'margin-left:.5in'><span =
style=3D'font-size:8.0pt;font-family:"Courier =
New"'> =
<price>21.79</price><o:p></o:p></span></p><p =
class=3DMsoPlainText style=3D'margin-left:.5in'><span =
style=3D'font-size:8.0pt;font-family:"Courier =
New"'> =
<quantity>2</quantity><o:p></o:p></span></p><p =
class=3DMsoPlainText style=3D'margin-left:.5in'><span =
style=3D'font-size:8.0pt;font-family:"Courier New"'> =
</line-item><o:p></o:p></span></p><p class=3DMsoPlainText =
style=3D'margin-left:.5in'><span =
style=3D'font-size:8.0pt;font-family:"Courier New"'> =
<line-item><o:p></o:p></span></p><p class=3DMsoPlainText =
style=3D'margin-left:.5in'><span =
style=3D'font-size:8.0pt;font-family:"Courier =
New"'> =
<description>Burnham's Celestial Handbook, Vol =
2</description><o:p></o:p></span></p><p class=3DMsoPlainText =
style=3D'margin-left:.5in'><span =
style=3D'font-size:8.0pt;font-family:"Courier =
New"'> =
<per-unit-ounces>5</per-unit-ounces><o:p></o:p></span></p><p =
class=3DMsoPlainText style=3D'margin-left:.5in'><span =
style=3D'font-size:8.0pt;font-family:"Courier =
New"'> =
<price>19.89</price><o:p></o:p></span></p><p =
class=3DMsoPlainText style=3D'margin-left:.5in'><span =
style=3D'font-size:8.0pt;font-family:"Courier =
New"'> =
<quantity>2</quantity><o:p></o:p></span></p><p =
class=3DMsoPlainText style=3D'margin-left:.5in'><span =
style=3D'font-size:8.0pt;font-family:"Courier New"'> =
</line-item><o:p></o:p></span></p><p class=3DMsoPlainText =
style=3D'margin-left:.5in'><span =
style=3D'font-size:8.0pt;font-family:"Courier New"'> =
<shipper><o:p></o:p></span></p><p class=3DMsoPlainText =
style=3D'margin-left:.5in'><span =
style=3D'font-size:8.0pt;font-family:"Courier =
New"'> =
<name>ZipShip</name><o:p></o:p></span></p><p =
class=3DMsoPlainText style=3D'margin-left:.5in'><span =
style=3D'font-size:8.0pt;font-family:"Courier =
New"'> =
<per-ounce-rate>0.74</per-ounce-rate><o:p></o:p></span></p><p=
class=3DMsoPlainText style=3D'margin-left:.5in'><span =
style=3D'font-size:8.0pt;font-family:"Courier New"'> =
</shipper><o:p></o:p></span></p><p class=3DMsoPlainText =
style=3D'margin-left:.5in'><span =
style=3D'font-size:8.0pt;font-family:"Courier =
New"'></purchase-order><o:p></o:p></span></p><p =
class=3DMsoPlainText style=3D'margin-left:.5in'><span =
style=3D'font-size:8.0pt;font-family:"Courier =
New"'><o:p> </o:p></span></p><p class=3DMsoPlainText =
style=3D'margin-left:.5in'><span =
style=3D'font-size:8.0pt;font-family:"Courier New"'>LINE ITEM =
ADDED<o:p></o:p></span></p><p class=3DMsoPlainText =
style=3D'margin-left:.5in'><span =
style=3D'font-size:8.0pt;font-family:"Courier New"'><purchase-order =
xmlns=3D"http://openuri.org/easypo"><o:p></o:p></span></p><p=
class=3DMsoPlainText style=3D'margin-left:.5in'><span =
style=3D'font-size:8.0pt;font-family:"Courier New"'> =
<customer><o:p></o:p></span></p><p class=3DMsoPlainText =
style=3D'margin-left:.5in'><span =
style=3D'font-size:8.0pt;font-family:"Courier =
New"'> <name>Gladys =
Kravitz</name><o:p></o:p></span></p><p class=3DMsoPlainText =
style=3D'margin-left:.5in'><span =
style=3D'font-size:8.0pt;font-family:"Courier =
New"'> <address>Anytown, =
PA</address><o:p></o:p></span></p><p class=3DMsoPlainText =
style=3D'margin-left:.5in'><span =
style=3D'font-size:8.0pt;font-family:"Courier New"'> =
</customer><o:p></o:p></span></p><p class=3DMsoPlainText =
style=3D'margin-left:.5in'><span =
style=3D'font-size:8.0pt;font-family:"Courier New"'> =
<date>2003-01-07T14:16:00-05:00</date><o:p></o:p></span></p><=
p class=3DMsoPlainText style=3D'margin-left:.5in'><span =
style=3D'font-size:8.0pt;font-family:"Courier New"'> =
<line-item><o:p></o:p></span></p><p class=3DMsoPlainText =
style=3D'margin-left:.5in'><span =
style=3D'font-size:8.0pt;font-family:"Courier =
New"'> =
<description>Burnham's Celestial Handbook, Vol =
1</description><o:p></o:p></span></p><p class=3DMsoPlainText =
style=3D'margin-left:.5in'><span =
style=3D'font-size:8.0pt;font-family:"Courier =
New"'> =
<per-unit-ounces>5</per-unit-ounces><o:p></o:p></span></p><p =
class=3DMsoPlainText style=3D'margin-left:.5in'><span =
style=3D'font-size:8.0pt;font-family:"Courier =
New"'> =
<price>21.79</price><o:p></o:p></span></p><p =
class=3DMsoPlainText style=3D'margin-left:.5in'><span =
style=3D'font-size:8.0pt;font-family:"Courier =
New"'> =
<quantity>2</quantity><o:p></o:p></span></p><p =
class=3DMsoPlainText style=3D'margin-left:.5in'><span =
style=3D'font-size:8.0pt;font-family:"Courier New"'> =
</line-item><o:p></o:p></span></p><p class=3DMsoPlainText =
style=3D'margin-left:.5in'><span =
style=3D'font-size:8.0pt;font-family:"Courier New"'> =
<line-item><o:p></o:p></span></p><p class=3DMsoPlainText =
style=3D'margin-left:.5in'><span =
style=3D'font-size:8.0pt;font-family:"Courier =
New"'> =
<description>Burnham's Celestial Handbook, Vol =
2</description><o:p></o:p></span></p><p class=3DMsoPlainText =
style=3D'margin-left:.5in'><span =
style=3D'font-size:8.0pt;font-family:"Courier =
New"'> =
<per-unit-ounces>5</per-unit-ounces><o:p></o:p></span></p><p =
class=3DMsoPlainText style=3D'margin-left:.5in'><span =
style=3D'font-size:8.0pt;font-family:"Courier =
New"'> =
<price>19.89</price><o:p></o:p></span></p><p =
class=3DMsoPlainText style=3D'margin-left:.5in'><span =
style=3D'font-size:8.0pt;font-family:"Courier =
New"'> =
<quantity>2</quantity><o:p></o:p></span></p><p =
class=3DMsoPlainText style=3D'margin-left:.5in'><span =
style=3D'font-size:8.0pt;font-family:"Courier New"'> =
</line-item><o:p></o:p></span></p><p class=3DMsoPlainText =
style=3D'margin-left:.5in'><span =
style=3D'font-size:8.0pt;font-family:"Courier New"'> =
<line-item><description>foo</description><per-unit-o=
unces>1</per-unit-ounces><price>2</price><quantit=
y>3</quantity></line-item><shipper><o:p></o:p></span=
></p><p class=3DMsoPlainText style=3D'margin-left:.5in'><span =
style=3D'font-size:8.0pt;font-family:"Courier =
New"'> =
<name>ZipShip</name><o:p></o:p></span></p><p =
class=3DMsoPlainText style=3D'margin-left:.5in'><span =
style=3D'font-size:8.0pt;font-family:"Courier =
New"'> =
<per-ounce-rate>0.74</per-ounce-rate><o:p></o:p></span></p><p=
class=3DMsoPlainText style=3D'margin-left:.5in'><span =
style=3D'font-size:8.0pt;font-family:"Courier New"'> =
</shipper><o:p></o:p></span></p><p class=3DMsoPlainText =
style=3D'margin-left:.5in'><span =
style=3D'font-size:8.0pt;font-family:"Courier =
New"'></purchase-order><o:p></o:p></span></p><p =
class=3DMsoPlainText style=3D'margin-left:.5in'><span =
style=3D'font-size:8.0pt;font-family:"Courier =
New"'><o:p> </o:p></span></p><p class=3DMsoPlainText =
style=3D'margin-left:.5in'><span =
style=3D'font-size:8.0pt;font-family:"Courier New"'>LINE ITEM =
DELETED<o:p></o:p></span></p><p class=3DMsoPlainText =
style=3D'margin-left:.5in'><span =
style=3D'font-size:8.0pt;font-family:"Courier New"'><purchase-order =
xmlns=3D"http://openuri.org/easypo"><o:p></o:p></span></p><p=
class=3DMsoPlainText style=3D'margin-left:.5in'><span =
style=3D'font-size:8.0pt;font-family:"Courier New"'> =
<customer><o:p></o:p></span></p><p class=3DMsoPlainText =
style=3D'margin-left:.5in'><span =
style=3D'font-size:8.0pt;font-family:"Courier =
New"'> <name>Gladys =
Kravitz</name><o:p></o:p></span></p><p class=3DMsoPlainText =
style=3D'margin-left:.5in'><span =
style=3D'font-size:8.0pt;font-family:"Courier =
New"'> <address>Anytown, =
PA</address><o:p></o:p></span></p><p class=3DMsoPlainText =
style=3D'margin-left:.5in'><span =
style=3D'font-size:8.0pt;font-family:"Courier New"'> =
</customer><o:p></o:p></span></p><p class=3DMsoPlainText =
style=3D'margin-left:.5in'><span =
style=3D'font-size:8.0pt;font-family:"Courier New"'> =
<date>2003-01-07T14:16:00-05:00</date><o:p></o:p></span></p><=
p class=3DMsoPlainText style=3D'margin-left:.5in'><span =
style=3D'font-size:8.0pt;font-family:"Courier New"'> =
<o:p></o:p></span></p><p class=3DMsoPlainText =
style=3D'margin-left:.5in'><span =
style=3D'font-size:8.0pt;font-family:"Courier =
New"'> <line-item><o:p></o:p></span></p><p =
class=3DMsoPlainText style=3D'margin-left:.5in'><span =
style=3D'font-size:8.0pt;font-family:"Courier =
New"'> =
<description>Burnham's Celestial Handbook, Vol =
2</description><o:p></o:p></span></p><p class=3DMsoPlainText =
style=3D'margin-left:.5in'><span =
style=3D'font-size:8.0pt;font-family:"Courier =
New"'> =
<per-unit-ounces>5</per-unit-ounces><o:p></o:p></span></p><p =
class=3DMsoPlainText style=3D'margin-left:.5in'><span =
style=3D'font-size:8.0pt;font-family:"Courier =
New"'> =
<price>19.89</price><o:p></o:p></span></p><p =
class=3DMsoPlainText style=3D'margin-left:.5in'><span =
style=3D'font-size:8.0pt;font-family:"Courier =
New"'> =
<quantity>2</quantity><o:p></o:p></span></p><p =
class=3DMsoPlainText style=3D'margin-left:.5in'><span =
style=3D'font-size:8.0pt;font-family:"Courier New"'> =
</line-item><o:p></o:p></span></p><p class=3DMsoPlainText =
style=3D'margin-left:.5in'><span =
style=3D'font-size:8.0pt;font-family:"Courier New"'> =
<line-item><description>foo</description><per-unit-o=
unces>1</per-unit-ounces><price>2</price><quantit=
y>3</quantity></line-item><shipper><o:p></o:p></span=
></p><p class=3DMsoPlainText style=3D'margin-left:.5in'><span =
style=3D'font-size:8.0pt;font-family:"Courier =
New"'> =
<name>ZipShip</name><o:p></o:p></span></p><p =
class=3DMsoPlainText style=3D'margin-left:.5in'><span =
style=3D'font-size:8.0pt;font-family:"Courier =
New"'> =
<per-ounce-rate>0.74</per-ounce-rate><o:p></o:p></span></p><p=
class=3DMsoPlainText style=3D'margin-left:.5in'><span =
style=3D'font-size:8.0pt;font-family:"Courier New"'> =
</shipper><o:p></o:p></span></p><p class=3DMsoPlainText =
style=3D'margin-left:.5in'><span =
style=3D'font-size:8.0pt;font-family:"Courier =
New"'></purchase-order><o:p></o:p></span></p><p =
class=3DMsoPlainText style=3D'margin-left:.5in'><span =
style=3D'font-size:8.0pt;font-family:"Courier =
New"'><o:p> </o:p></span></p><p class=3DMsoPlainText =
style=3D'margin-left:.5in'><span =
style=3D'font-size:8.0pt;font-family:"Courier New"'>COPY OF DELETED LINE =
ITEM<o:p></o:p></span></p><p class=3DMsoPlainText =
style=3D'margin-left:.5in'><span =
style=3D'font-size:8.0pt;font-family:"Courier New"'><xml-fragment =
xmlns:eas=3D"http://openuri.org/easypo"><o:p></o:p></span></=
p><p class=3DMsoPlainText style=3D'margin-left:.5in'><span =
style=3D'font-size:8.0pt;font-family:"Courier New"'> =
<eas:description>Burnham's Celestial Handbook, Vol =
1</eas:description><o:p></o:p></span></p><p class=3DMsoPlainText =
style=3D'margin-left:.5in'><span =
style=3D'font-size:8.0pt;font-family:"Courier New"'> =
<eas:per-unit-ounces>5</eas:per-unit-ounces><o:p></o:p></span=
></p><p class=3DMsoPlainText style=3D'margin-left:.5in'><span =
style=3D'font-size:8.0pt;font-family:"Courier New"'> =
<eas:price>21.79</eas:price><o:p></o:p></span></p><p =
class=3DMsoPlainText style=3D'margin-left:.5in'><span =
style=3D'font-size:8.0pt;font-family:"Courier New"'> =
<eas:quantity>2</eas:quantity><o:p></o:p></span></p><p =
class=3DMsoPlainText style=3D'margin-left:.5in'><span =
style=3D'font-size:8.0pt;font-family:"Courier =
New"'></xml-fragment><o:p></o:p></span></p><p =
class=3DMsoPlainText><o:p> </o:p></p><p class=3DMsoPlainText>On the =
other hand I might be completely FOS. Please let me know if this =
is the case.<o:p></o:p></p><p =
class=3DMsoPlainText><o:p> </o:p></p><p =
class=3DMsoPlainText>Cordially,<o:p></o:p></p><p =
class=3DMsoPlainText>Paul Gillen<o:p></o:p></p><p =
class=3DMsoPlainText><o:p> </o:p></p><p =
class=3DMsoPlainText><o:p> </o:p></p><p =
class=3DMsoPlainText><o:p> </o:p></p><p =
class=3DMsoPlainText>-----Original Message-----<br>From: Lott, =
Christopher M [mailto:[email protected]] <br>Sent: Monday, August 19, =
2013 9:33 PM<br>To: <[email protected]><br>Subject: Re: =
Modifying XmlBeans document without XmlValueDisconnectedException?</p><p =
class=3DMsoPlainText><o:p> </o:p></p><p class=3DMsoPlainText>Thanks =
to Nick B. and Paul G. for their quick replies! Below is code that =
demonstrates, at least superficially, the exception that we get. =
We are doing something wrong in our code; I don't suspect an XmlBeans =
bug at this point. This code is derived from (and depends on the =
schema and example XML instance from) the XmlBeans tutorial at <a =
href=3D"http://xmlbeans.apache.org/documentation/tutorial_getstarted.html=
"><span =
style=3D'color:windowtext;text-decoration:none'>http://xmlbeans.apache.or=
g/documentation/tutorial_getstarted.html</span></a><o:p></o:p></p><p =
class=3DMsoPlainText><o:p> </o:p></p><p =
class=3DMsoPlainText>--<o:p></o:p></p><p class=3DMsoPlainText>package =
my.xb.example;<o:p></o:p></p><p =
class=3DMsoPlainText><o:p> </o:p></p><p class=3DMsoPlainText>import =
java.io.File;<o:p></o:p></p><p class=3DMsoPlainText>import =
java.math.BigDecimal;<o:p></o:p></p><p class=3DMsoPlainText>import =
java.math.BigInteger;<o:p></o:p></p><p =
class=3DMsoPlainText><o:p> </o:p></p><p class=3DMsoPlainText>import =
org.openuri.easypo.LineItem;<o:p></o:p></p><p =
class=3DMsoPlainText>import =
org.openuri.easypo.PurchaseOrderDocument;<o:p></o:p></p><p =
class=3DMsoPlainText><o:p> </o:p></p><p class=3DMsoPlainText>public =
class POUpdater {<o:p></o:p></p><p =
class=3DMsoPlainText> &nbs=
p; public static void main(String[] =
args) throws Exception {<o:p></o:p></p><p =
class=3DMsoPlainText> &nbs=
p;  =
; if =
(args.length < 5)<o:p></o:p></p><p =
class=3DMsoPlainText> &nbs=
p;  =
; =
&=
nbsp; throw new Exception("Usage: inputfile desc ounces price =
quantity");<o:p></o:p></p><p =
class=3DMsoPlainText> &nbs=
p;  =
; File =
poXmlFile =3D new File(args[0]);<o:p></o:p></p><p =
class=3DMsoPlainText> &nbs=
p;  =
; String =
updatedPoXml =3D addLineItem(poXmlFile, args[1], args[2], =
args[3],<o:p></o:p></p><p =
class=3DMsoPlainText> &nbs=
p;  =
; =
&=
nbsp; &n=
bsp; args[4]);<o:p></o:p></p><p =
class=3DMsoPlainText> &nbs=
p;  =
; =
System.out.println(updatedPoXml);<o:p></o:p></p><p =
class=3DMsoPlainText> &nbs=
p; }<o:p></o:p></p><p =
class=3DMsoPlainText><o:p> </o:p></p><p =
class=3DMsoPlainText> &nbs=
p; private static String =
addLineItem(File purchaseOrder,<o:p></o:p></p><p =
class=3DMsoPlainText> &nbs=
p;  =
; =
&=
nbsp; String itemDescription, String =
perUnitOuncesString,<o:p></o:p></p><p =
class=3DMsoPlainText> &nbs=
p;  =
; =
&=
nbsp; String itemPriceString, String itemQuantityString) throws =
Exception {<o:p></o:p></p><p =
class=3DMsoPlainText> &nbs=
p;  =
; =
<o:p></o:p></p><p =
class=3DMsoPlainText> &nbs=
p;  =
; // Read in =
the file content<o:p></o:p></p><p =
class=3DMsoPlainText> &nbs=
p;  =
; =
PurchaseOrderDocument poDoc =3D =
PurchaseOrderDocument.Factory<o:p></o:p></p><p =
class=3DMsoPlainText> &nbs=
p;  =
; =
&=
nbsp; &n=
bsp; =
.parse(purchaseOrder);<o:p></o:p></p><p =
class=3DMsoPlainText><o:p> </o:p></p><p =
class=3DMsoPlainText> &nbs=
p;  =
; // Convert =
incoming data to types that can be used in accessors.<o:p></o:p></p><p =
class=3DMsoPlainText> &nbs=
p;  =
; BigDecimal =
perUnitOunces =3D new BigDecimal(perUnitOuncesString);<o:p></o:p></p><p =
class=3DMsoPlainText> &nbs=
p;  =
; BigDecimal =
itemPrice =3D new BigDecimal(itemPriceString);<o:p></o:p></p><p =
class=3DMsoPlainText> &nbs=
p;  =
; BigInteger =
itemQuantity =3D new BigInteger(itemQuantityString);<o:p></o:p></p><p =
class=3DMsoPlainText><o:p> </o:p></p><p =
class=3DMsoPlainText> &nbs=
p;  =
; // Add a =
new <line-item> element.<o:p></o:p></p><p =
class=3DMsoPlainText> &nbs=
p;  =
; LineItem =
newItem =3D poDoc.getPurchaseOrder().addNewLineItem();<o:p></o:p></p><p =
class=3DMsoPlainText> &nbs=
p;  =
; =
newItem.setDescription(itemDescription);<o:p></o:p></p><p =
class=3DMsoPlainText> &nbs=
p;  =
; =
newItem.setPerUnitOunces(perUnitOunces);<o:p></o:p></p><p =
class=3DMsoPlainText> &nbs=
p;  =
; =
newItem.setPrice(itemPrice);<o:p></o:p></p><p =
class=3DMsoPlainText> &nbs=
p;  =
; =
newItem.setQuantity(itemQuantity);<o:p></o:p></p><p =
class=3DMsoPlainText><o:p> </o:p></p><p =
class=3DMsoPlainText> &nbs=
p;  =
; // Delete =
the old first line item<o:p></o:p></p><p =
class=3DMsoPlainText> &nbs=
p;  =
; LineItem =
removedItem =3D =
poDoc.getPurchaseOrder().getLineItemArray(0);<o:p></o:p></p><p =
class=3DMsoPlainText> &nbs=
p;  =
; =
poDoc.getPurchaseOrder().removeLineItem(0);<o:p></o:p></p><p =
class=3DMsoPlainText><o:p> </o:p></p><p =
class=3DMsoPlainText> &nbs=
p;  =
; // Try to =
access the newly added one; is the ref still good?<o:p></o:p></p><p =
class=3DMsoPlainText> &nbs=
p; =
&=
nbsp; System.out.println("new item: " + =
newItem.toString());<o:p></o:p></p><p =
class=3DMsoPlainText> &nbs=
p;  =
; =
newItem.setDescription(newItem.getDescription() + " =
fu");<o:p></o:p></p><p class=3DMsoPlainText><o:p> </o:p></p><p =
class=3DMsoPlainText> &nbs=
p;  =
; // Try to =
access the removed one; this throws =
XmlValueDisconnectedException<o:p></o:p></p><p =
class=3DMsoPlainText> &nbs=
p;  =
; =
System.out.println("removed item: " + =
removedItem.toString());<o:p></o:p></p><p =
class=3DMsoPlainText> &nbs=
p;  =
; =
<o:p></o:p></p><p =
class=3DMsoPlainText> &nbs=
p;  =
; return =
poDoc.toString();<o:p></o:p></p><p =
class=3DMsoPlainText> &nbs=
p; }<o:p></o:p></p><p =
class=3DMsoPlainText>}<o:p></o:p></p><p =
class=3DMsoPlainText><o:p> </o:p></p><p =
class=3DMsoPlainText><o:p> </o:p></p><p =
class=3DMsoPlainText><o:p> </o:p></p><p =
class=3DMsoPlainText><o:p> </o:p></p><p =
class=3DMsoPlainText>----------------------------------------------------=
-----------------<o:p></o:p></p><p class=3DMsoPlainText>To unsubscribe, =
e-mail: <a href=3D"mailto:[email protected]"><span =
style=3D'color:windowtext;text-decoration:none'>user-unsubscribe@xmlbeans=
.apache.org</span></a><o:p></o:p></p><p class=3DMsoPlainText>For =
additional commands, e-mail: <a =
href=3D"mailto:[email protected]"><span =
style=3D'color:windowtext;text-decoration:none'>[email protected]=
.org</span></a><o:p></o:p></p><p =
class=3DMsoPlainText><o:p> </o:p></p></div></body></html>
------=_NextPart_000_00CD_01CE9D29.D822EAB0--