xpath query

S

Sebastian Paral

Hi, i got an xml database like this:

<conferencemanager>

<person pid="p1"><name>Sebastian</name></person>
<person pid="p2"><name>Christian</name></person>
<person pid="p3"><name>Maria</name></person>
<person pid="p4"><name>Georg</name></person>
<person pid="p5"><name>Sabine</name></person>

<conference kid="k1">
<name>Conference Nr. 1</name>
<date>10.10.2005</date>
<location>Graz</location>
</conference>

<conference kid="k2">
<name>Conference Nr. 2</name>
<date>10.10.2005</date>
<location>Vienna</location>
</conference>

<conference kid="k3">
<name>Konferenz Nr. 3</name>
<date>10.10.2005</date>
<location>Vienna</location>
</conference>

<lecture vid="v1"><title>DBMS</title></lecture>
<lecture vid="v2"><title>Distributed Systems</title></lecture>
<lecture vid="v3"><title>Computer Science</title></lecture>

<attendance pid="p1" kid="k1" vid="v1" />
<attendance pid="p2" kid="k2" vid="v2" />
<attendance pid="p3" kid="k2" vid="v1" />
<attendance pid="p4" kid="k2" vid="v1" />
<attendance pid="p5" kid="k2" vid="v1" />
<attendance pid="p5" kid="k3" vid="v3" />
<attendance pid="p3" kid="k2" vid="v1" />

</conferencemanager>

my assignment is as follows:
find all names (person) which have ever seen (attendance) conferences
(conference) in "vienna" about the "DBMS" lecture. this query should be
created with xpath.

in xquery it would be:

for $p in /conferencemanager/person,
$k in /conferencemanager/conference,
$v in /conferencemanager/lecture,
$t in /conferencemanager/attendance
where $t/@pid = $p/@pid and $t/@kid = $k/@kid and $t/@vid = $v/@vid
and $v/title = "DBMS" and $k/location = "Vienna"
return string($p/name)

is there a possibility to create an equivalent query only with xpath?
thanks for any help!

regards
 
R

Richard Tobin

Sebastian Paral said:
my assignment is as follows:
find all names (person) which have ever seen (attendance) conferences
(conference) in "vienna" about the "DBMS" lecture. this query should be
created with xpath.

in xquery it would be:

for $p in /conferencemanager/person,
$k in /conferencemanager/conference,
$v in /conferencemanager/lecture,
$t in /conferencemanager/attendance
where $t/@pid = $p/@pid and $t/@kid = $k/@kid and $t/@vid = $v/@vid
and $v/title = "DBMS" and $k/location = "Vienna"
return string($p/name)

is there a possibility to create an equivalent query only with xpath?
thanks for any help!

Yes. You want the name of a person who was had an attendance:

//person[@pid = //attendance[...]/@pid]/name

Where the attendance has a conference with location Vienna:

@kid = //conference[location="Vienna"]/@kid

and a lecture with subject DBMS:

@vid = //lecture[title = "DBMS"]/@vid]

So put the second and third expressions in the predicate of the first.

-- Richard
 
S

Sebastian Paral

Yes. You want the name of a person who was had an attendance:
//person[@pid = //attendance[...]/@pid]/name

Where the attendance has a conference with location Vienna:

@kid = //conference[location="Vienna"]/@kid

and a lecture with subject DBMS:

@vid = //lecture[title = "DBMS"]/@vid]

So put the second and third expressions in the predicate of the first.

-- Richard

Hey, nice going... thank you very much!
regards
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,999
Messages
2,570,243
Members
46,836
Latest member
login dogas

Latest Threads

Top