- PR -

xindiceデータベースの更新はできません

1
投稿者投稿内容
フェー
会議室デビュー日: 2003/01/20
投稿数: 4
投稿日時: 2003-01-20 11:39
皆さん、こんにちは、最近、XindiceというXMLデータベースを勉強しております、
”Xindice:無料で使えるXMLデータベース”をよく利用しています。
しかし、最後のXMLデータの更新と削除という部分はうまくできていません。
http://www.atmarkit.co.jp/fxml/tanpatsu/18xindice/xindice09.html
にあるXUpdate.javaというサンプルの実行結果は"Number: 1"であるはずですが、
わたしの実行結果は"Number: 0 "つまり、更新できませんでした。
 私はそのデータをコマンドプロンプトで調べました、確かにそのデータが存在しています。
これは環境の問題ですか、ソースコードの問題ですか、または、何かの問題ですか、
私は良く分かっていません。助けていただきたいんです。
環境:java1.3 OS:windows2000

 参考のために、自分が実行したソースコードも以下のように一緒に記述しています。
よろしく、お願いします
以上

--------------- XUpdate.java -----------------------

import org.xmldb.api.base.*;
import org.xmldb.api.modules.*;
import org.xmldb.api.*;
import org.w3c.dom.*;
import java.io.*;

public class XUpdate {
public static void main(String[] args) throws Exception {
if (args.length != 1) {
System.err.println("java XUpdate [ファイル名]");
return;
}
String filename = args[0];

Collection col = null;
try {
// 1. Database実装クラスの登録
String driver = "org.apache.xindice.client.xmldb.DatabaseImpl";
Class c = Class.forName(driver);
Database database = (Database) c.newInstance();
DatabaseManager.registerDatabase(database);

// 2. コレクションの取得
col = DatabaseManager.getCollection("xmldb:xindice:///db/sampledb");

// 3. XUpdateQueryServiceの取得
org.xmldb.api.modules.XUpdateQueryService service = (org.xmldb.api.modules.XUpdateQueryService)
col.getService("XUpdateQueryService", "1.0");

// 5. XUpdateで更新
BufferedReader reader = new BufferedReader(new FileReader(filename));
StringBuffer xupdate = new StringBuffer();
try {
String line;
final String lineSeparator = System.getProperty("line.separator");
while (null != (line = reader.readLine())) {
xupdate.append(line);
xupdate.append(lineSeparator);
}
long num = service.update(xupdate.toString());
System.err.println("Number: " + num);
}
catch (IOException e) {
System.err.println("IO Exception occured");
System.err.println(e);
}
finally {
reader.close();
}
}
catch (XMLDBException e) {
System.err.println("XML:DB Exception occured " + e.errorCode);
System.err.println(e);
}
finally {
if (col != null) {
// 6. コレクションのクローズ
col.close();
}
}
}
}

--------------- update.xml  -----------------------
<xupdate:modifications version="1.0" xmlns:xupdate="http://www.xmldb.org/xupdate">
<xupdate:update select="problem[@id='ID0002']/@status">closed</xupdate:update>
</xupdate:modifications>

----------------- 実行結果 ----------------
Number: 0

-------  データの存在を確認する   ----------

C:\>xindice xpath -c /db/sampledb -q "/problem[@id='ID0002']"
<?xml version="1.0"?>
<problem id="ID0002" status="open" title="core dump" date="2001-12-28" xmlns:src="http://xml.apache.org/x
indice/Query" src:col="/db/sampledb" src:key="prob2">
<description>
サーバがコア・ダンプする。
</description>
<actions>
<action who="A_company">
<description>
開発元に問合せ。
</description>
</action>
<action who="C_customer">
<description>
情報収集
</description>
</action>
</actions>
</problem>
C:\>

1

スキルアップ/キャリアアップ(JOB@IT)