package org.apache.xindice.examples;
/*
* Copyright 1999-2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* CVS $Id: XUpdate.java,v 1.7 2004/02/08 01:19:43 vgritsenko Exp $
*/
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 XUpdate extends AbstractExample {
public static void main(String[] args) throws Exception {
Collection collection = null;
try {
collection = getCollection("xmldb:xindice:///db/addressbook");
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>";
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();
}
}
}
}