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 Vanessa Williams <v....@acm.org> on 2002/06/25 22:26:48 UTC

Xindice xpath queries and namespaces

I'm still struggling with exceptions being thrown related to namespaces, but
I've narrowed down the problem.

Take this example document:

<a:foo xmlns:a="http://www.somedomain.com/someschema.xsd">
    <b:bar xmlns:b="http://www/somedomain.com/someschema2.xsd">
    </b:bar>
</a:foo>

The document is well-formed and valid and is added to a Xindice collection
(say /db/test).

The problem is what XPath expression to use to get it out:

xindice xpath -c /db/test -q /a:foo

Will throw an exception because "a" doesn't map to a namespace in the query
itself. 

So, I'm assuming it needs the URI instead, but can't find any examples of
how to do that in XPath:

xindice xpath -c /db/test -q "/http://www.somedomain.com/someschema.xsd:foo"

doesn't work either. Neither does:

xindice xpath -c /db/test -q
"'/http://www.somedomain.com/someschema.xsd':foo"


The XPath spec has no examples related to this.


Anyone have any ideas?


Thanks,

Vanessa


Re: Xindice xpath queries and namespaces

Posted by Ugo Cei <u....@cbim.it>.
Vanessa Williams wrote:
> I'm still struggling with exceptions being thrown related to namespaces, but
> I've narrowed down the problem.

<snip/>

It's even worse than it appears. I've recently discovered this: suppose 
you have a collection /db/nstest, containing two documents:

/db/nstest/a:

	<?xml version="1.0"?>
	<a:a xmlns:a="http://a/" />

/db/nstest/b:

	<?xml version="1.0"?>
	<b:b xmlns:b="http://b/" />

What would you expect the following query to return?

	xindice xpath -c xindice://localhost:4080/db/nstest -q '/a:a'

Well, it turns out it returns this:

<?xml version="1.0"?>
<a:a xmlns:a="http://a/" xmlns:src="http://xml.apache.org/xindice/Query" 
src:col="/db/nstest" src:key="a" />
<?xml version="1.0"?>
<b:b xmlns:b="http://b/" xmlns:src="http://xml.apache.org/xindice/Query" 
src:col="/db/nstest" src:key="b" />

This happens even if the query is random, e.g. the same results are 
returned for '/x:y'!

Is this a known bug or what?

	Ugo

-- 
Ugo Cei - Consorzio di Bioingegneria e Informatica Medica
P.le Volontari del Sangue, 2 - 27100 Pavia - Italy
Phone: +39.0382.525100 - E-mail: u.cei@cbim.it


Re: Xindice xpath queries and namespaces

Posted by Vanessa Williams <v....@acm.org>.
If you use something like this:

xindice xpath -c /db/junk -s "glop=http://blah" -q "//glop:zork"

the result is unambiguous:

<?xml version="1.0"?>
  <zork xmlns="http://blah" xmlns:src="http://xml.apache.org/xindice/Query"
src:col="/db/xones/tupletest" src:key="nstest"
xmlns:glop="http://blah">abc</zork>

And

<?xml version="1.0"?>
<glop:zork xmlns:src="http://xml.apache.org/xindice/Query"
src:col="/db/xones/tupletest" src:key="nstest"
xmlns:glop="http://blah">xyz</glop:zork>

(these are actual results)

Your point is well taken, though: XPath is at best ambiguous with respect to
namespaces because it matches only on prefixes, not URIs. As long as the
context for the query/xpath expression is properly defined beforehand, it's
not a problem.

Dare Obasanjo wrote:

> 
> --- Jeff Greif <jg...@alumni.princeton.edu> wrote:
>> Vanessa and Xindice developers,
>> In the prior version (dbxml-1.0b4), using this
>> document in the collection
>> /db/junk,
>> 
>> <?xml version="1.0" ?>
>> <fur modtime="0"
>> owner="/sysinfo/Webalo/users/sysroot"
>> xmlns:glop="http://blah">
>>   <ObjectId collection="junk" host="localhost"
>>             glop:urk="/rootview~!~">
>>     <Uname>/rootview</Uname><VmcName></VmcName>
>>   </ObjectId>
>>   <glop:zork>xyz</glop:zork>
>>   <Body>
>>   </Body>
>> </fur>
>> 
>> the following queries worked as expected
>> 
>> dbxml xpath -c /db/junk -q "//glop:zork"
> 
> 
> And what is the expected result? How about if the XML
> was 
> 
> <?xml version="1.0" ?>
> <fur modtime="0"
> owner="/sysinfo/Webalo/users/sysroot"
> xmlns:glop="http://blah">
>  <zork xmlns="http://blah">abc</zork>
>  <glop:zork>xyz</glop:zork>
>  <glop:zork
> xmlns:glop="http://example.com">123</glop>
>  <Body>
>  </Body>
> </fur>
> 
> My bad for being pedantic, I'll go back to lurking. :)
> 
> =====
> THINGS TO DO IF I BECOME AN EVIL OVERLORD #79
> If my doomsday device happens to come with a reverse switch, as soon as it has
> been employed it will be melted down and made into limited-edition
> commemorative coins.
> 
> __________________________________________________
> Do You Yahoo!?
> Yahoo! - Official partner of 2002 FIFA World Cup
> http://fifaworldcup.yahoo.com


Re: Xindice xpath queries and namespaces

Posted by Dare Obasanjo <kp...@yahoo.com>.
--- Jeff Greif <jg...@alumni.princeton.edu> wrote:
> Vanessa and Xindice developers,
> In the prior version (dbxml-1.0b4), using this
> document in the collection
> /db/junk,
> 
> <?xml version="1.0" ?>
> <fur modtime="0"
> owner="/sysinfo/Webalo/users/sysroot"
> xmlns:glop="http://blah">
>   <ObjectId collection="junk" host="localhost"
>             glop:urk="/rootview~!~">
>     <Uname>/rootview</Uname><VmcName></VmcName>
>   </ObjectId>
>   <glop:zork>xyz</glop:zork>
>   <Body>
>   </Body>
> </fur>
> 
> the following queries worked as expected
> 
> dbxml xpath -c /db/junk -q "//glop:zork"


And what is the expected result? How about if the XML
was 

 <?xml version="1.0" ?>
 <fur modtime="0"
 owner="/sysinfo/Webalo/users/sysroot"
 xmlns:glop="http://blah">
   <zork xmlns="http://blah">abc</zork>
   <glop:zork>xyz</glop:zork>
   <glop:zork
xmlns:glop="http://example.com">123</glop>
   <Body>
   </Body>
 </fur>

My bad for being pedantic, I'll go back to lurking. :) 

=====
THINGS TO DO IF I BECOME AN EVIL OVERLORD #79
If my doomsday device happens to come with a reverse switch, as soon as it has been employed it will be melted down and made into limited-edition commemorative coins.

__________________________________________________
Do You Yahoo!?
Yahoo! - Official partner of 2002 FIFA World Cup
http://fifaworldcup.yahoo.com

Re: Xindice xpath queries and namespaces

Posted by Jeff Greif <jg...@alumni.princeton.edu>.
Vanessa and Xindice developers,
In the prior version (dbxml-1.0b4), using this document in the collection
/db/junk,

<?xml version="1.0" ?>
<fur modtime="0" owner="/sysinfo/Webalo/users/sysroot"
xmlns:glop="http://blah">
  <ObjectId collection="junk" host="localhost"
            glop:urk="/rootview~!~">
    <Uname>/rootview</Uname><VmcName></VmcName>
  </ObjectId>
  <glop:zork>xyz</glop:zork>
  <Body>
  </Body>
</fur>

the following queries worked as expected

dbxml xpath -c /db/junk -q "//glop:zork"
dbxml xpath -c /db/junk -q "//ObjectId[@glop:urk]"

while this one returned nothing as expected
dbxml xpath -c /db/junk -q "//ObjectId[@glop:burk]"

and this one gets an exception as expected
dbxml xpath -c /db/junk -q "//p:zork"

In xindice-1.0, all the queries got exceptions; however, the second one
above still managed to return the correct value.  So the namespace stuff in
xpath queries got broken between versions.

Jeff



Re: Xindice xpath queries and namespaces

Posted by Vanessa Williams <v....@acm.org>.

Mark J. Stang wrote:

> Don't need no stinkin namespaces ;-).   I try to be as vanilla
> as possible.   No namespaces, DTDs or anything out of the
> ordinary.


Hmmm...an interesting form of purism :) However, in real-life namespaces are
essential and therefore quite ordinary.

I've figured out my problem and I'm patching up the command-line tool to
deal with it. I'll forward the patch to the list as soon as it's done.

Cheers,

Vanessa


Re: Xindice xpath queries and namespaces

Posted by "Mark J. Stang" <ma...@earthlink.net>.
Don't need no stinkin namespaces ;-).   I try to be as vanilla
as possible.   No namespaces, DTDs or anything out of the
ordinary.

Vanessa Williams wrote:

> Thanks for the idea, Roman. I tried it, but unfortunately, it doesn't work.
> :-(
>
> I did manage to discover that XPath itself does not support namespaces in
> any way. It uses only the prefixes and depends on "the system" (for
> instance, an XSLT stylesheet processor) to define a context (i.e. To map
> those prefixes to namespace uris). So it seems unlikely that the
> command-line tool can support namespaces at all, in its current form.
>
> This isn't so much a problem for me if I can figure out how to make the
> queries work through the XPathQueryService API. I have an idea I'll try
> later today. If it works, it may be possible to rewrite the command-line
> tool to take another parameter (like: -s
> "a=http://www.somedomain.com/someschema.xsd;b=http://www/somedomain.com/some
> schema2.xsd) so that queries like /a:foo will work properly.
>
> I'm surprised I haven't seen more messages on this topic. Is it just that
> most people using Xindice aren't using namespaces?
>
> Vanessa
>
> KOZLOV Roman wrote:
>
> > Hi Vanessa,
> >
> > Perhaps it is possible to use notation as for indexing (see
> > http://localhost:4080/AdministratorsGuide.html#N46):
> >
> > ". . .
> > Note: In order to index a namespace other than the default namespace, you must
> > prepend your pattern components with a URI placed in square brackets. Example:
> >
> > [http://www.world.org/People]person
> > *@[http://www.world.org/People]id
> > [http://www.world.org/People]person@[http://www.world.org/People]id
> >
> > Do not include a prefix in these patterns, as the indexing system, like most
> > Namespace processing applications, processes namespaced elements and
> > attributes
> > independently of the prefix that is used. "
> >
> > Roman
> >
> > Vanessa Williams wrote:
> >
> >> I'm still struggling with exceptions being thrown related to namespaces, but
> >> I've narrowed down the problem.
> >>
> >> Take this example document:
> >>
> >> <a:foo xmlns:a="http://www.somedomain.com/someschema.xsd">
> >>     <b:bar xmlns:b="http://www/somedomain.com/someschema2.xsd">
> >>     </b:bar>
> >> </a:foo>
> >>
> >> The document is well-formed and valid and is added to a Xindice collection
> >> (say /db/test).
> >>
> >> The problem is what XPath expression to use to get it out:
> >>
> >> xindice xpath -c /db/test -q /a:foo
> >>
> >> Will throw an exception because "a" doesn't map to a namespace in the query
> >> itself.
> >>
> >> So, I'm assuming it needs the URI instead, but can't find any examples of
> >> how to do that in XPath:
> >>
> >> xindice xpath -c /db/test -q "/http://www.somedomain.com/someschema.xsd:foo"
> >>
> >> doesn't work either. Neither does:
> >>
> >> xindice xpath -c /db/test -q
> >> "'/http://www.somedomain.com/someschema.xsd':foo"
> >>
> >> The XPath spec has no examples related to this.
> >>
> >> Anyone have any ideas?
> >>
> >> Thanks,
> >>
> >> Vanessa
> >

--
Mark J Stang
System Architect
Cybershop Systems


Re: Xindice xpath queries and namespaces

Posted by Vanessa Williams <v....@acm.org>.
Thanks for the idea, Roman. I tried it, but unfortunately, it doesn't work.
:-(

I did manage to discover that XPath itself does not support namespaces in
any way. It uses only the prefixes and depends on "the system" (for
instance, an XSLT stylesheet processor) to define a context (i.e. To map
those prefixes to namespace uris). So it seems unlikely that the
command-line tool can support namespaces at all, in its current form.

This isn't so much a problem for me if I can figure out how to make the
queries work through the XPathQueryService API. I have an idea I'll try
later today. If it works, it may be possible to rewrite the command-line
tool to take another parameter (like: -s
"a=http://www.somedomain.com/someschema.xsd;b=http://www/somedomain.com/some
schema2.xsd) so that queries like /a:foo will work properly.

I'm surprised I haven't seen more messages on this topic. Is it just that
most people using Xindice aren't using namespaces?

Vanessa

KOZLOV Roman wrote:

> Hi Vanessa,
> 
> Perhaps it is possible to use notation as for indexing (see
> http://localhost:4080/AdministratorsGuide.html#N46):
> 
> ". . .
> Note: In order to index a namespace other than the default namespace, you must
> prepend your pattern components with a URI placed in square brackets. Example:
> 
> [http://www.world.org/People]person
> *@[http://www.world.org/People]id
> [http://www.world.org/People]person@[http://www.world.org/People]id
> 
> Do not include a prefix in these patterns, as the indexing system, like most
> Namespace processing applications, processes namespaced elements and
> attributes
> independently of the prefix that is used. "
> 
> Roman
> 
> Vanessa Williams wrote:
> 
>> I'm still struggling with exceptions being thrown related to namespaces, but
>> I've narrowed down the problem.
>> 
>> Take this example document:
>> 
>> <a:foo xmlns:a="http://www.somedomain.com/someschema.xsd">
>>     <b:bar xmlns:b="http://www/somedomain.com/someschema2.xsd">
>>     </b:bar>
>> </a:foo>
>> 
>> The document is well-formed and valid and is added to a Xindice collection
>> (say /db/test).
>> 
>> The problem is what XPath expression to use to get it out:
>> 
>> xindice xpath -c /db/test -q /a:foo
>> 
>> Will throw an exception because "a" doesn't map to a namespace in the query
>> itself.
>> 
>> So, I'm assuming it needs the URI instead, but can't find any examples of
>> how to do that in XPath:
>> 
>> xindice xpath -c /db/test -q "/http://www.somedomain.com/someschema.xsd:foo"
>> 
>> doesn't work either. Neither does:
>> 
>> xindice xpath -c /db/test -q
>> "'/http://www.somedomain.com/someschema.xsd':foo"
>> 
>> The XPath spec has no examples related to this.
>> 
>> Anyone have any ideas?
>> 
>> Thanks,
>> 
>> Vanessa
> 


Re: Xindice xpath queries and namespaces

Posted by KOZLOV Roman <r-...@opencascade.com>.
Hi Vanessa,

Perhaps it is possible to use notation as for indexing (see
http://localhost:4080/AdministratorsGuide.html#N46):

". . .
Note: In order to index a namespace other than the default namespace, you must
prepend your pattern components with a URI placed in square brackets. Example:

[http://www.world.org/People]person
*@[http://www.world.org/People]id
[http://www.world.org/People]person@[http://www.world.org/People]id

Do not include a prefix in these patterns, as the indexing system, like most
Namespace processing applications, processes namespaced elements and attributes
independently of the prefix that is used. "

Roman

Vanessa Williams wrote:

> I'm still struggling with exceptions being thrown related to namespaces, but
> I've narrowed down the problem.
>
> Take this example document:
>
> <a:foo xmlns:a="http://www.somedomain.com/someschema.xsd">
>     <b:bar xmlns:b="http://www/somedomain.com/someschema2.xsd">
>     </b:bar>
> </a:foo>
>
> The document is well-formed and valid and is added to a Xindice collection
> (say /db/test).
>
> The problem is what XPath expression to use to get it out:
>
> xindice xpath -c /db/test -q /a:foo
>
> Will throw an exception because "a" doesn't map to a namespace in the query
> itself.
>
> So, I'm assuming it needs the URI instead, but can't find any examples of
> how to do that in XPath:
>
> xindice xpath -c /db/test -q "/http://www.somedomain.com/someschema.xsd:foo"
>
> doesn't work either. Neither does:
>
> xindice xpath -c /db/test -q
> "'/http://www.somedomain.com/someschema.xsd':foo"
>
> The XPath spec has no examples related to this.
>
> Anyone have any ideas?
>
> Thanks,
>
> Vanessa