我正在使用 BaseX 本机 XML 数据库来查询 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
来自爪哇?