- From: Jonathan Robie <jonathan.robie@datadirect-technologies.com>
- Date: Thu, 31 Oct 2002 13:35:10 -0500
- To: "Marko Smiljanic" <markosm@cs.utwente.nl>, <www-ql@w3.org>
At 11:17 AM 10/30/2002 +0100, Marko Smiljanic wrote: >We can assume that the XML schema designer had a specific semantics in mind >when he specified that a sequence <A/><B/> should repeat it self. E.g. <A/> >can be the name of a man and <B/> can be his address. We thus have from 1 to >5 pairs of person name / person address (where address does not have to be >specified). >Note that each single person is represented by one sequence. I can say that >sequence has a clear semantics i.e. 1 sequence = 1 person. (and each person >has a name and an address) On the other hand, we can also assume that this is not an experienced schema designer. If your data reflects a concept as important as a person, that person should be reflected in the markup. So I think that your schema designer should have used a structure that looks more like: <person> <name>Marko Smiljanic</name> <address>P.O. Box 217, 7500 AE Enschede, The Netherlands</address> </person> Still, it can be queried, but the queries will be less natural than for a well-designed schema. >My questions are: > >a) How can we specify a query in XQuery language saying that I'm interested >in 2nd persons address (i.e. <B>). (The answer should be empty for the >example above). In your schema, this is the same as asking for the first element that follows the second A, if that element happens to be a B. let $r := input()/root, $a2 := ($r/A)[2], {-- the second A --} $next := ($r/*[ . >> $a2])[1] {-- the first element after the second A --} return if (local-name($next) eq 'B') then $next else () >b) This is similar to the problem in a): is there any way that that I can >count the number of A,B sequences in an instance XML document (using >XQuery). (The example above has 3 sequences). That's easy - for the schema you provided, this is the same as the number of A elements. Each sequence has precisely one A element: count( input()/root/A ) Hope this helps! Jonathan
Received on Thursday, 31 October 2002 13:35:44 UTC