//package org.apache.xindice.examples;



import org.xmldb.api.base.Collection;
import org.xmldb.api.base.XMLDBException;
import org.xmldb.api.modules.XUpdateQueryService;



/**
 * Simple XML:DB API example to update the database.
 */
public class XUpdateA  extends AbstractExample {
    
    public static void main(String[] args) throws Exception {
        Collection collection = null;
        try {

           // collection = getCollection("xmldb:xindice:///db/addressbook");
            collection = getCollection("xmldb:xindice-embed:///db/mycollection100");
           /* String xupdate =
                "<xu:modifications version=\"1.0\""
                    + "      xmlns:xu=\"http://www.xmldb.org/xupdate\">"
                    + "   <xu:remove select=\"/person/phone[@type = 'home']\"/>"
                    + "   <xu:update select=\"/person/phone[@type = 'work']\">"
                    + "       480-300-3003"
                    + "   </xu:update>"
                    + "</xu:modifications>"; **/
                    
             String xupdate =
                "<xu:modifications version=\"1.0\""
                    + "      xmlns:xu=\"http://www.xmldb.org/xupdate\">"
                    + "   <xu:remove select=\"/parts/part[@sku = '103']/model\"/>"
                    + "   <xu:update select=\"/parts/part[@sku ='102']/price\">"
                    + "       $31.00" 
                    + "   </xu:update>"
                    + "</xu:modifications>";

            XUpdateQueryService service = (XUpdateQueryService) collection.getService("XUpdateQueryService", "1.0");
            long count = service.update(xupdate);
            System.out.println(count + " entries updated.");
        } catch (XMLDBException e) {
            System.err.println("XML:DB Exception occured " + e.errorCode + " " + e.getMessage());
        } finally {
            if (collection != null) {
                collection.close();
            }
        }
    }
}
