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 Steven Shand <de...@intrallect.com> on 2004/04/27 18:51:17 UTC
default namespace problems
Hi,
I'm having some issues searching documents within a default namespace.
if my document looks like
<node1 xmlns="http://foo.bar.com" >
<bar>content</bar>
</node1>
I'd assume that I would do service.setNamespace( "",
"xmlns="http://foo.bar.com" )
or even
service.setNamespace( null, "xmlns="http://foo.bar.com" )
neither of these work.
However if I add a prefix to my document like:
<foo:node1 xmlns:foo="http://foo.bar.com" >
<foo:bar>content</foo:bar>
</foo:node1>
and do service.setNamespace( "foo", "xmlns="http://foo.bar.com" )
my query works fine. Unfortunately this isn't a solution for me.
I came across something in the archives which seemed to say that as
long as I called setNamespace() with the location value, it didn't
really matter what was passed as a prefix. I've tried this and it
certainly doesn't work.
If anybody has some ideas on this I'd appreciate some feedback. It
seems like a very common use-case. I'm sure I must be missing
something.
I'm using the 1.1b4 build.
Thanks.
Steven Shand.
Re: default namespace problems
Posted by Vadim Gritsenko <va...@reverycodes.com>.
Murray Altheim wrote:
> Vadim Gritsenko wrote:
>
>> Steven Shand wrote:
>>
>>
>>> Hi,
>>>
>>> I'm having some issues searching documents within a default namespace.
>>>
>>> if my document looks like
>>>
>>> <node1 xmlns="http://foo.bar.com" >
>>> <bar>content</bar>
>>> </node1>
>>>
>>> I'd assume that I would do service.setNamespace( "",
>>> "xmlns="http://foo.bar.com" )
>>>
>>> or even
>>>
>>> service.setNamespace( null, "xmlns="http://foo.bar.com" )
>>>
>>> neither of these work.
>>> However if I add a prefix to my document like:
>>>
>>> <foo:node1 xmlns:foo="http://foo.bar.com" >
>>> <foo:bar>content</foo:bar>
>>> </foo:node1>
>>>
>>> and do service.setNamespace( "foo", "xmlns="http://foo.bar.com" )
>>>
>>> my query works fine. Unfortunately this isn't a solution for me.
>>
You are right and service.setNamespace( "", "...") does not work, but
you don't have to change your document to perform a query - namespace
prefix in the document and namespace prefix in the query does not have
to match. Just use any non-empty prefix in your query (like 'foo'), and
it will work (see my other email with simple example).
Vadim
Re: default namespace problems
Posted by Murray Altheim <m....@open.ac.uk>.
Vadim Gritsenko wrote:
> Steven Shand wrote:
>
>
>>Hi,
>>
>>I'm having some issues searching documents within a default namespace.
>>
>>if my document looks like
>>
>><node1 xmlns="http://foo.bar.com" >
>> <bar>content</bar>
>></node1>
>>
>>I'd assume that I would do service.setNamespace( "",
>>"xmlns="http://foo.bar.com" )
>>
>>or even
>>
>>service.setNamespace( null, "xmlns="http://foo.bar.com" )
>>
>>neither of these work.
>>However if I add a prefix to my document like:
>>
>><foo:node1 xmlns:foo="http://foo.bar.com" >
>> <foo:bar>content</foo:bar>
>></foo:node1>
>>
>>and do service.setNamespace( "foo", "xmlns="http://foo.bar.com" )
>>
>>my query works fine. Unfortunately this isn't a solution for me.
>>
>>I came across something in the archives which seemed to say that as
>>long as I called setNamespace() with the location value, it didn't
>>really matter what was passed as a prefix. I've tried this and it
>>certainly doesn't work.
>>
>>If anybody has some ideas on this I'd appreciate some feedback. It
>>seems like a very common use-case. I'm sure I must be missing
>>something.
>>I'm using the 1.1b4 build.
>
>
>
> I tried
> bin\xindice xpath -c /db/test -n ns -s a=http://foo.bar.com -q
> "/a:foo/a:bar"
> with the document above and it did not work. Seems like a bug. If you
> find a solution to it, send a patch to the dev list. In either case, you
> can use bugzilla to track this issue.
Vadim,
Can't do much myself right now, but I did note on upgrading from 1.0
to 1.1 that the setNamespace() method had all changed and broken (?)
in the transition, so it's probably in the method itself. (If this
is any help...). In my own application code I just commented out all
of the setNamespace stuff since I've not yet got around to working
out my own bugs with XPath.
Murray
......................................................................
Murray Altheim http://kmi.open.ac.uk/people/murray/
Knowledge Media Institute
The Open University, Milton Keynes, Bucks, MK7 6AA, UK .
The Resume of George W. Bush
http://www.buzzflash.com/contributors/03/04/23_resume.html
Re: default namespace problems
Posted by Steven Shand <de...@intrallect.com>.
>> I'm having some issues searching documents within a default namespace.
>>
>> if my document looks like
>>
>> <node1 xmlns="http://foo.bar.com" >
>> <bar>content</bar>
>> </node1>
>>
>
> I tried
> bin\xindice xpath -c /db/test -n ns -s a=http://foo.bar.com -q
> "/a:foo/a:bar"
> with the document above and it did not work. Seems like a bug. If you
> find a solution to it, send a patch to the dev list. In either case,
> you can use bugzilla to track this issue.
>
> Vadim
I'll hopefully get some time at the start of next week to look into
this further.
Steven.
Re: default namespace problems
Posted by Vadim Gritsenko <va...@reverycodes.com>.
Steven Shand wrote:
> Hi,
>
> I'm having some issues searching documents within a default namespace.
>
> if my document looks like
>
> <node1 xmlns="http://foo.bar.com" >
> <bar>content</bar>
> </node1>
>
> I'd assume that I would do service.setNamespace( "",
> "xmlns="http://foo.bar.com" )
>
> or even
>
> service.setNamespace( null, "xmlns="http://foo.bar.com" )
>
> neither of these work.
> However if I add a prefix to my document like:
>
> <foo:node1 xmlns:foo="http://foo.bar.com" >
> <foo:bar>content</foo:bar>
> </foo:node1>
>
> and do service.setNamespace( "foo", "xmlns="http://foo.bar.com" )
>
> my query works fine. Unfortunately this isn't a solution for me.
>
> I came across something in the archives which seemed to say that as
> long as I called setNamespace() with the location value, it didn't
> really matter what was passed as a prefix. I've tried this and it
> certainly doesn't work.
>
> If anybody has some ideas on this I'd appreciate some feedback. It
> seems like a very common use-case. I'm sure I must be missing
> something.
> I'm using the 1.1b4 build.
I tried
bin\xindice xpath -c /db/test -n ns -s a=http://foo.bar.com -q
"/a:foo/a:bar"
with the document above and it did not work. Seems like a bug. If you
find a solution to it, send a patch to the dev list. In either case, you
can use bugzilla to track this issue.
Vadim