You are on page 1of 3

XQUERY

employee.xml
<Employee_Info>
<Employee Employee_Number="109">
<Name>Hanu</Name>
<Department>CSE Department</Department>
<Telephone>03-1452-4567</Telephone>
<Email>hanu.mrce@mrei.ac.in</Email>
<salary>20000</salary>
</Employee>
<Employee Employee_Number="102">
<Name>Babita Ahuja</Name>
<Department>I.T. Department</Department>
<Telephone>03-6459-98764</Telephone>
<Email>babita.mrce@mrei.ac.in</Email>
<salary>30000</salary>
</Employee>
<Employee Employee_Number="103">
<Name>Neelu Choudhary</Name>
<Department>CSE Department</Department>
<Telephone>03-6459-98764</Telephone>
<Email>neelu.mrce@mrei.ac.in</Email>
<salary>40000</salary>
</Employee>
<Employee Employee_Number="104">
<Name>Nikita Taneja</Name>
<Department>CSE Department</Department>
<Telephone>03-6129-98764</Telephone>
<Email>nikita.mrce@mrei.ac.in</Email>
<salary>50000</salary>
</Employee>
<Employee Employee_Number="105">
<Name>Ritu Saluja</Name>
<Department>CSE Department</Department>
<Telephone>03-1259-98764</Telephone>
<Email>ritu.mrce@mrei.ac.in</Email>
<salary>60000</salary>
</Employee>
<Employee Employee_Number="106">
<Name>Jyoti Pruthi</Name>
<Department>IT Department</Department>
<Telephone>01-1159-98764</Telephone>
<Email>Jyoti.mrce@mrei.ac.in</Email>
<salary>70000</salary>
</Employee>
</Employee_Info>

Query 1: Query function doc(): used to open the XML file .


doc("employee.xml")

Query 2: Path Expression: Navigate through elements


doc("employee.xml")//Telephone

Query 3: Predicates: Limit the extracted data


doc("employee.xml")//Employee[salary<40000]/Name

Query 4: FLWOR:

[for] [let] [where] [order by] [return]

for $x in doc("employee.xml")/Employee_Info/Employee
where $x//salary<40000
return $x//Name

Query 5: Order by
for $x in doc("employee.xml")/Employee_Info/Employee
where $x//salary<40000
order by $x//Name
return $x//Name

Query 6: Presentation in HTML


<ul>
{
for $x in doc("employee.xml")/Employee_Info/Employee
where $x//salary<40000
order by $x//Name
return <li> {$x//Name} </li>
}
</ul>

university.xml

<university>
<department>
<hod>Sachin</hod>
<budget>
<consumable>6000</consumable>
<non_consumable>5000</non_consumable>
</budget>
<num_faculty>23</num_faculty>
<num_ug_stud>120</num_ug_stud>
<num_pg_stud>18</num_pg_stud>
</department>
<department>
<hod>Shailee</hod>
<budget>
<consumable>5000</consumable>
<non_consumable>6000</non_consumable>
</budget>
<num_faculty>12</num_faculty>
<num_ug_stud>60</num_ug_stud>
<num_pg_stud>18</num_pg_stud>
</department>
<department>
<hod>Sangeeta</hod>
<budget>
<consumable>5000</consumable>
<non_consumable>7000</non_consumable>
</budget>
<num_faculty>20</num_faculty>
<num_ug_stud>60</num_ug_stud>
<num_pg_stud>18</num_pg_stud>
</department>
</university>

Query: Extract the name of hod of the department having consumable budget =
5000. {According to query 3, 4,6}
Query: Extract the name of hod of the department having consumable budget =
5000 ordered by num_faculty.

You might also like