You are viewing a plain text version of this content. The canonical link for it is here.
Posted to xindice-users@xml.apache.org by Simon Farrow <s....@umist.ac.uk> on 2003/06/11 18:25:16 UTC

Querying with namespaces

I realize that this was discussed a little while ago but I couldn't seem
to find any final answer. I'm trying to query a document that uses
namespaces throughout. Not using namespaces is not an option for us. An
excerpt from the document is below:

<?xml version="1.0" encoding="UTF-8"?>
<ns1:ObsProject xmlns:ns1="Alma/ObsPrep/ObsProject">
    <ns1:ObsProjectEntity entityId="uid://X0000000000000001/X00000100"
        entityIdEncrypted="-- id encryption not yet implemented --"
entityTypeName="ObsProject"/>
    <ns1:ObsProposalRef entityId="uid://X0000000000000001/X00000101"
        entityTypeName="ObsProposal" entityVersion="latest"/>
    <ns1:ObsProgram code="aaa">

the query I'm trying to perform is very simple

/ns1:ObsProject

This should select every document with this root node in the database.

all this is being done with code that looks like:

service = (XPathQueryService)collection.getService("XPathQueryService",
"1.0");
ResourceSet resultSet= service.query(query);

where query is the string obove.

this query causes an exception to be thrown:
org.xmldb.api.base.XMLDBException: Query error

Does anyone have any clue how I can get this query to return something.
The same query without the namespace returns no results.

Thanks,

Simon Farrow.




RE: Querying with namespaces

Posted by Simon Farrow <s....@umist.ac.uk>.
So I'm going to end up passing in an array of all of the namespaces used
in a particular query. I think that i may have a cunning plan ;-). I'm
thinking that I can grab all of the namespaces as documents are
submitted and then load them all in advance so they are there for any
querying. Is there any kind of limit on the number that i can have set
and any time?

Thanks for the rapid response.

Simon.

> You need to use the setNamespace method of the XPathQueryService, to specify
> any prefix to namespace mappings that you are going to use within your
> query. For example:
> 
> service =
> (XPathQueryService)collection.getService("XPathQueryService","1.0");
> service.setNamespace("ns1","Alma/ObsPrep/ObsProject");
> ResourceSet resultSet= service.query(query);
> 
> - Tom
> 
> -----Original Message-----
> From: Simon Farrow [mailto:s.farrow@umist.ac.uk]
> Sent: Wednesday, June 11, 2003 5:25 PM
> To: xindice users
> Subject: Querying with namespaces
> 
> 
> I realize that this was discussed a little while ago but I couldn't seem
> to find any final answer. I'm trying to query a document that uses
> namespaces throughout. Not using namespaces is not an option for us. An
> excerpt from the document is below:
> 
> <?xml version="1.0" encoding="UTF-8"?>
> <ns1:ObsProject xmlns:ns1="Alma/ObsPrep/ObsProject">
>     <ns1:ObsProjectEntity entityId="uid://X0000000000000001/X00000100"
>         entityIdEncrypted="-- id encryption not yet implemented --"
> entityTypeName="ObsProject"/>
>     <ns1:ObsProposalRef entityId="uid://X0000000000000001/X00000101"
>         entityTypeName="ObsProposal" entityVersion="latest"/>
>     <ns1:ObsProgram code="aaa">
> 
> the query I'm trying to perform is very simple
> 
> /ns1:ObsProject
> 
> This should select every document with this root node in the database.
> 
> all this is being done with code that looks like:
> 
> service = (XPathQueryService)collection.getService("XPathQueryService",
> "1.0");
> ResourceSet resultSet= service.query(query);
> 
> where query is the string obove.
> 
> this query causes an exception to be thrown:
> org.xmldb.api.base.XMLDBException: Query error
> 
> Does anyone have any clue how I can get this query to return something.
> The same query without the namespace returns no results.
> 
> Thanks,
> 
> Simon Farrow.
> 
> 
> 
> 



RE: Querying with namespaces

Posted by Tom Sugden <to...@epcc.ed.ac.uk>.
You need to use the setNamespace method of the XPathQueryService, to specify
any prefix to namespace mappings that you are going to use within your
query. For example:

service =
(XPathQueryService)collection.getService("XPathQueryService","1.0");
service.setNamespace("ns1","Alma/ObsPrep/ObsProject");
ResourceSet resultSet= service.query(query);

- Tom

-----Original Message-----
From: Simon Farrow [mailto:s.farrow@umist.ac.uk]
Sent: Wednesday, June 11, 2003 5:25 PM
To: xindice users
Subject: Querying with namespaces


I realize that this was discussed a little while ago but I couldn't seem
to find any final answer. I'm trying to query a document that uses
namespaces throughout. Not using namespaces is not an option for us. An
excerpt from the document is below:

<?xml version="1.0" encoding="UTF-8"?>
<ns1:ObsProject xmlns:ns1="Alma/ObsPrep/ObsProject">
    <ns1:ObsProjectEntity entityId="uid://X0000000000000001/X00000100"
        entityIdEncrypted="-- id encryption not yet implemented --"
entityTypeName="ObsProject"/>
    <ns1:ObsProposalRef entityId="uid://X0000000000000001/X00000101"
        entityTypeName="ObsProposal" entityVersion="latest"/>
    <ns1:ObsProgram code="aaa">

the query I'm trying to perform is very simple

/ns1:ObsProject

This should select every document with this root node in the database.

all this is being done with code that looks like:

service = (XPathQueryService)collection.getService("XPathQueryService",
"1.0");
ResourceSet resultSet= service.query(query);

where query is the string obove.

this query causes an exception to be thrown:
org.xmldb.api.base.XMLDBException: Query error

Does anyone have any clue how I can get this query to return something.
The same query without the namespace returns no results.

Thanks,

Simon Farrow.