I tried to track this bug down a while ago: It appeared to me at the
time that there was a problem within the Xalan implementation which is
used for XPath evaluation. When I stepped through the SAX events that
occur when parsing the query string, it did not appear that the prefix
resolver was being invoked when the query path had an unqualified (i.e.
default) element or attribute. I was never able to find the time to dig
any deeper.
The good news is that you can work around the problem pretty easily.
Even if your schema document is stored using a default namespace (as
shown in your second example), you can perform the query using a
non-default query. So, you should be able to store your document as in
Example 2. When you want to perform your query, you can use the query
syntax from your first example. As long as you've set the namespace on
your service as you've specified:
service.setNamespace( "xsd", "http://www.w3.org/2001/XMLSchema"
);
Then everything should work with the query
"/xsd:schema/xsd:[EMAIL PROTECTED]'FooType']". It does not matter if
the "xsd" prefix is not used in the document that is stored.
I still plan to look into this bug if I get a chance, but my schedule's
been pretty tight lately.
Hope that helps!
- Tim
> -----Original Message-----
> From: Richard Martell [mailto:[EMAIL PROTECTED]
> Sent: Friday, February 08, 2002 3:59 PM
> To: [email protected]
> Subject: XPath queries: nodes in default namespace not returned
>
>
> 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
>
>
>