XML ファイルのクエリに BaseX ネイティブ XML データベースを使用しています。BaseX ドキュメントで提供されている BaseXClient.java ファイルを使用しています。basex サーバーを起動し、BaseXClient.java を使用してサーバーに接続しています。
// create session
final BaseXClient session = new BaseXClient("localhost", 1984, "admin", "admin");
String query = "doc('xmlfiles/juicers.xml')//image";
// version 1: perform command and print returned string
System.out.println(session.execute(query));
これで、juicers.xml ファイルにxmlns
情報が含まれるようになりました。
<?xml version="1.0"?>
<juicers
xmlns="http://www.juicers.org"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.juicers.org
juicers.xsd">
<juicer>
<name>OJ Home Juicer</name>
<image>images\mighty_oj.gif</image>
<description>There's just no substitute for a properly squeezed
orange in the morning. So delicate and refreshing. The finest hotels
use mechanical juicers of this type for their most discriminating
guests. This is the largest selling juicer of its kind. It's a
beautiful little all-metal piece in baked enamel and polished chrome;
it even won the Frankfurt Fair Award for its design. Uses no
electricity and produces no non-recyclable waste as do frozen juices.
</description>
<warranty>lifetime warranty</warranty>
<cost>41.95</cost>
<retailer>http://www.thewhitewhale.com/oj.htm</retailer>
</juicer>
</juicers>
xmlns
XML インスタンス ファイル (juicers.xml) を指定しないと、正しい結果が返されます。ただしxmlns
、XML インスタンス ファイルに含まれている場合は、次の例外がスローされます。
java.io.IOException: Stopped at line 1, column 3:
Expecting command.
at org.basex.api.BaseXClient.execute(BaseXClient.java:73)
at org.basex.api.BaseXClient.execute(BaseXClient.java:84)
at org.basex.api.Example.main(Example.java:31)
を使用して XML インスタンス ファイルをクエリするにはどうすればよいxmlns
ですか? 抜け道はありますか?xquery
Javaから実行する他の方法はありますか?