I've got some XML with namespaces and I just can't find a way to set the namespace in my query.
If I do (Using a standard Connection in java):
statement.execute(
"SELECT ID, " +
"XMLSERIALIZE( " +
"XMLQUERY('/' PASSING BY REF Definition EMPTY
ON EMPTY) " +
"AS VARCHAR(10000)) " +
"FROM My_Schema.My_Table");
Where my XML looks like:
<tns:MyProject xmlns:tns="http://www.myproject.ox.ac.uk/MyProject"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.myproject.ox.ac.uk/MyProject MyProject.xsd">
<tns:Name>Douglas</tns:Name>
</tns:MyProject>
and my database is just 2 columns: ID (Varchar) and Definition (XML).
The XPATH '/' gets all the XML in Definition, that works. If I try and search
for '//Name' however, I get nothing. Presumably this is because Name is
actually in a namespace. How do I construct my XPATH to look for this?
I've tried:
'//myns:Name' and that would seem to be correct, but I can find no way of
setting myns to resolve to "http://www.myproject.ox.ac.uk/MyProject" in
Derby. When I do that I just get the error:
Caused by: org.apache.derby.client.am.SqlException: Encountered error while
evaluating XML query expression for XMLQUERY operator: Prefix must resolve to
a namespace: myns SQLSTATE: XJ001: Java exception: 'Prefix must resolve to a
namespace: myns: org.apache.xpath.domapi.XPathStylesheetDOM3Exception'.
Any help would be much appreciated.
Cheers
--
Douglas PW Russell
Research Officer - GIMI/NeuroGrid
Oxford University Computing Laboratory
Tel: +44 (0)1865 283519
email: [EMAIL PROTECTED]
pgpJ8jYmL2mtg.pgp
Description: PGP signature
