Hi,


I'm not having much success executing XPath queries against documents with a default namespace declared (using the beta4 release). According to the XML:DB spec, if the prefix input to the setNamespace() method is null or empty, the default namespace is set.

e.g.
. . .
 XPathQueryService service =
            (XPathQueryService) col.getService("XPathQueryService", "1.0");
 service.setNamespace( null, defaultNamespaceURI );
. . .


But the query comes up empty having set the namespaces as follows (see examples 1 and 2 below):

service.setNamespace( "", http://www.w3.org/2001/XMLSchema );
service.setNamespace( "xsd", "http://www.w3.org/2001/XMLSchema"; );


Example 1--this works (returns the matching type definition) ============================================================ String xpath = "/xsd:schema/xsd:[EMAIL PROTECTED]'FooType']";

where this schema is in the target collection:

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema targetNamespace="http://www.foo.net/bar";
  xmlns:bar="http://www.foo.net/bar";
  xmlns:xsd="http://www.w3.org/2001/XMLSchema";
  elementFormDefault="qualified">

  <xsd:element name="Foo" type="bar:FooType" />
  <xsd:complexType name="FooType">
    <xsd:sequence>
       <xsd:element name="alpha" type="xsd:string" />
    </xsd:sequence>
    <xsd:attribute name="id" type="xsd:ID" use="optional"/>
  </xsd:complexType>
</xsd:schema>


Example 2--this doesn't work (empty result set) =============================================== String xpath = "/schema/[EMAIL PROTECTED]'FooType']";

where this equivalent schema is also in the target collection:

<?xml version="1.0" encoding="UTF-8"?>
<schema targetNamespace="http://www.foo.net/bar";
  xmlns:bar="http://www.foo.net/bar";
  xmlns="http://www.w3.org/2001/XMLSchema";
  elementFormDefault="qualified">

  <element name="Foo" type="bar:FooType" />
  <complexType name="FooType">
    <sequence>
       <element name="alpha" type="string" />
    </sequence>
    <attribute name="id" type="ID" use="optional"/>
  </complexType>
</schema>


Any suggestions, anyone?


- richard




Reply via email to