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

--
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: user-unsubscr...@xmlbeans.apache.org
For additional commands, e-mail: user-h...@xmlbeans.apache.org

Reply via email to