package org.apache.xindice.examples;
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.
*
* $Id: XUpdate.java 511428 2007-02-25 03:30:52Z vgritsenko $
*/
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();
}
}
}
}