私はBaseXネイティブXMLデータベースを使用してXMLファイルを照会しています。 BaseXのドキュメントで提供されているBaseXClient.javaファイルを使用しています。私はBaseXサーバーを起動し、BaseXClient.javaを使用してサーバーに接続しています。BaseXを使用してXMLファイルを照会
// 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>
私はXMLインスタンスファイル(juicers.xml)でxmlns
を与えていない場合、それは私に正しい結果を返します。 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)
xmlns
でXMLインスタンスファイルをクエリするにはどうすればよいですか?退出はありますか? Javaからxquery
を実行する他の方法はありますか?
ありがとうございました。しかし、私は、XMLインスタンスファイルに定義されているXML名前空間がない場合、またはxmlインスタンスファイルで指定されたスキーマファイル場所がない場合にのみクエリを実行できます。私は上記の存在、結果は返されません。この動作の特定の理由はありますか? –