Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: XML script
In below xml:
<mo>
    <customers>
    <customer cno="2222">
            <cname>Charles</cname>
            <street>123 Main St.</street>
            <city>Wichita</city>
            <zip>67226</zip>
            <phone>316-636-5555</phone>
        </customer>
        <customer cno="1000">
            <cname>Bismita</cname>
            <street>Ashford Dunwoody</street>
            <city>Wichita</city>
            <zip>67226-1555</zip>
            <phone>000-000-0000</phone>
        </customer>       
    </customers>
 
<pre>
&lt;employees&gt;
&lt;employee eno="1000"&gt;
        &lt;ename&gt;Jones&lt;/ename&gt;
        &lt;city&gt;Wichita&lt;/city&gt;
        &lt;zip&gt;67226-1555&lt;/zip&gt;
        &lt;hdate&gt;1995-12-12&lt;/hdate&gt;
    &lt;/employee&gt;
    &lt;employee eno="2000"&gt;
        &lt;ename&gt;Asmit&lt;/ename&gt;
        &lt;city&gt;Wichita&lt;/city&gt;
        &lt;zip&gt;67226-1555&lt;/zip&gt;
        &lt;hdate&gt;1967-08-13&lt;/hdate&gt;
    &lt;/employee&gt;
    &lt;employee eno="1003"&gt;
        &lt;ename&gt;Axaya&lt;/ename&gt;
        &lt;city&gt;BBSR&lt;/city&gt;
        &lt;zip&gt;67226&lt;/zip&gt;
        &lt;hdate&gt;1978-08-13&lt;/hdate&gt;
    &lt;/employee&gt;       
&lt;/employees&gt;
 
&lt;parts&gt;
    &lt;part pno="10506"&gt;            
        &lt;pname&gt;Land Before Time I&lt;/pname&gt;
        &lt;qoh&gt;200&lt;/qoh&gt;
        &lt;price&gt;319.99&lt;/price&gt;
        &lt;level&gt;20&lt;/level&gt;
    &lt;/part&gt;
    &lt;part pno="10000"&gt;            
        &lt;pname&gt;Bottle&lt;/pname&gt;
        &lt;qoh&gt;2&lt;/qoh&gt;
        &lt;price&gt;3.00&lt;/price&gt;
        &lt;level&gt;2&lt;/level&gt;
    &lt;/part&gt;
    &lt;part pno="10508"&gt;            
        &lt;pname&gt;Land Before Time 3&lt;/pname&gt;
        &lt;qoh&gt;202&lt;/qoh&gt;
        &lt;price&gt;2.00&lt;/price&gt;
        &lt;level&gt;22&lt;/level&gt;
    &lt;/part&gt;
    &lt;part pno="10509"&gt;            
        &lt;pname&gt;Cycle&lt;/pname&gt;
        &lt;qoh&gt;202&lt;/qoh&gt;
        &lt;price&gt;1.00&lt;/price&gt;
        &lt;level&gt;22&lt;/level&gt;
    &lt;/part&gt;
&lt;/parts&gt;
 
&lt;orders&gt;  
    &lt;order ono="1000" takenBy="1000" customer="2222" &gt;
        &lt;receivedDate&gt;1967-08-17&lt;/receivedDate&gt;
        &lt;shippedDate&gt;1967-08-13&lt;/shippedDate&gt;
        &lt;items&gt;
            &lt;item&gt;
                &lt;partNumber&gt;10508&lt;/partNumber&gt;
                &lt;quantity&gt;2&lt;/quantity&gt;
            &lt;/item&gt;
        &lt;/items&gt;
    &lt;/order&gt;
    &lt;order ono="1001" takenBy="1000" customer="1000" &gt;
        &lt;receivedDate&gt;1968-08-14&lt;/receivedDate&gt;
        &lt;shippedDate&gt;1968-08-11&lt;/shippedDate&gt;
        &lt;items&gt;
            &lt;item&gt;
                &lt;partNumber&gt;10000&lt;/partNumber&gt;
                &lt;quantity&gt;2&lt;/quantity&gt;
            &lt;/item&gt;
 
        &lt;/items&gt;
    &lt;/order&gt;
 
    &lt;order ono="1022" takenBy="1003"  customer="2222" &gt;
        &lt;receivedDate&gt;1995-02-14&lt;/receivedDate&gt;
        &lt;shippedDate&gt;1995-02-13&lt;/shippedDate&gt;
        &lt;items&gt;
            &lt;item&gt;
                &lt;partNumber&gt;10000&lt;/partNumber&gt;
                &lt;quantity&gt;1&lt;/quantity&gt;
            &lt;/item&gt;
            &lt;item&gt;
                &lt;partNumber&gt;10508&lt;/partNumber&gt;
                &lt;quantity&gt;2&lt;/quantity&gt;
            &lt;/item&gt;
            &lt;item&gt;
                &lt;partNumber&gt;10509&lt;/partNumber&gt;
                &lt;quantity&gt;3&lt;/quantity&gt;
            &lt;/item&gt;
        &lt;/items&gt;
    &lt;/order&gt;
 
&lt;/orders&gt;

</mo>
Two xquries are required.
1. Get the names of customers who have ordered parts from employees living in Wichita.
I have tried below xquery:
for
$c in /mo/customers/customer,
$e in /mo/employees/employee,
$p in /mo/parts/part,
$o in /mo/orders/order
where data($p/@pno)=$o/items/item/partNumber
and data($e/@eno)= data($o/@takenBy)
and $e/city='Wichita'
return $c/cname
Problem: Query returns duplicate values, how can I get distinct values ?
 
  1. Get the names of customers who have ordered parts only from employees living in Wichita.
    I have tried below xquery:
    for
    $c in /mo/customers/customer,
    $e in /mo/employees/employee,
    $p in /mo/parts/part,
    $o in /mo/orders/order
    where data($p/@pno)=$o/items/item/partNumber
    and data($e/@eno)= data($o/@takenBy)
    and data($e/city) eq("Wichita")
    return $c/cname
    Problem: Same result as query 1 with duplicate values.
Note: what should be the difference between two query by observing "living in Wichita and living only in wichita".

How can I get rid of returning duplicate values in these queries ?
Any help ?
Posted 20-Apr-13 19:52pm

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 490
1 Sergey Alexandrovich Kryukov 395
2 Maciej Los 285
3 ProgramFOX 265
4 CHill60 200
0 OriginalGriff 490
1 Sergey Alexandrovich Kryukov 395
2 Maciej Los 285
3 ProgramFOX 265
4 CHill60 200


Advertise | Privacy | Mobile
Web03 | 2.8.150331.1 | Last Updated 21 Apr 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100