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 "Grigorios D. Tsoumakas" <gr...@csd.auth.gr> on 2003/03/17 17:07:23 UTC

XPath query for an attribute value

Hi,

Does anyone know how can I retrieve the value for an
attribute of an element through an XPath Query...
using the Xindice XML:DB API?

For example suppose that I have the following element somewhere
in the xml document in Xindice:

<example shape="circle" color="red">
 
I use the following XPATH query to retrieve all "example"
elements with color "red":

//example[@color='red']

This works, but how do I get to the value of the shape attribute?

Alternatively I tried using the following XPATH query:

//example[@color='red']/@shape

This should actually return the value of the attribute, but it
does not return anything as a ResourceSet...

Any ideas?

----------------------------------------------------------------------
Grigorios D. Tsoumakas, Phd Student
Department of Informatics, Aristotle University of Thessaloniki
Thessaloniki 54124, Greece
tel: +30-310998418   fax: +30-310998419 
home page: http://users.auth.gr/~greg



Re: XPath query for an attribute value

Posted by "Mark J. Stang" <ma...@earthlink.net>.
The API doesn't support retrieving just an attribute.   You will get back
the element it is part of an you have to parse that.

hth,

Mark

George Papamarkos wrote:

> Geia sou Grigiri,
>
> That's a good question and an extension of the API that supports this
> kind of operations
> would be helpful indeed.
> The way I did it was by parsing the output !
> I could not find something smarted and faster.
>
> George
>
> PS: Basika auto einai ena provlima to opoio antimetopisa kai egw.
> Apo osa exw dei mexri ta twra den ypostirizetai kati tetoio apeu8eias
> paramono me parsing.
>
> Grigorios D. Tsoumakas wrote:
>
> >Hi,
> >
> >Does anyone know how can I retrieve the value for an
> >attribute of an element through an XPath Query...
> >using the Xindice XML:DB API?
> >
> >For example suppose that I have the following element somewhere
> >in the xml document in Xindice:
> >
> ><example shape="circle" color="red">
> >
> >I use the following XPATH query to retrieve all "example"
> >elements with color "red":
> >
> >//example[@color='red']
> >
> >This works, but how do I get to the value of the shape attribute?
> >
> >Alternatively I tried using the following XPATH query:
> >
> >//example[@color='red']/@shape
> >
> >This should actually return the value of the attribute, but it
> >does not return anything as a ResourceSet...
> >
> >Any ideas?
> >
> >----------------------------------------------------------------------
> >Grigorios D. Tsoumakas, Phd Student
> >Department of Informatics, Aristotle University of Thessaloniki
> >Thessaloniki 54124, Greece
> >tel: +30-310998418   fax: +30-310998419
> >home page: http://users.auth.gr/~greg
> >
> >
> >
> >
> >

--
Mark J Stang
System Architect
Cybershop Systems


Re: XPath query for an attribute value

Posted by George Papamarkos <g....@dcs.bbk.ac.uk>.
Geia sou Grigiri,

That's a good question and an extension of the API that supports this 
kind of operations
would be helpful indeed.
The way I did it was by parsing the output !
I could not find something smarted and faster.

George


PS: Basika auto einai ena provlima to opoio antimetopisa kai egw.
Apo osa exw dei mexri ta twra den ypostirizetai kati tetoio apeu8eias 
paramono me parsing.

Grigorios D. Tsoumakas wrote:

>Hi,
>
>Does anyone know how can I retrieve the value for an
>attribute of an element through an XPath Query...
>using the Xindice XML:DB API?
>
>For example suppose that I have the following element somewhere
>in the xml document in Xindice:
>
><example shape="circle" color="red">
> 
>I use the following XPATH query to retrieve all "example"
>elements with color "red":
>
>//example[@color='red']
>
>This works, but how do I get to the value of the shape attribute?
>
>Alternatively I tried using the following XPATH query:
>
>//example[@color='red']/@shape
>
>This should actually return the value of the attribute, but it
>does not return anything as a ResourceSet...
>
>Any ideas?
>
>----------------------------------------------------------------------
>Grigorios D. Tsoumakas, Phd Student
>Department of Informatics, Aristotle University of Thessaloniki
>Thessaloniki 54124, Greece
>tel: +30-310998418   fax: +30-310998419 
>home page: http://users.auth.gr/~greg
>
>
>
>  
>