0% found this document useful (0 votes)
44 views3 pages

XML Query

The document contains employee information from an XML file called employee.xml. It includes the names, departments, contact details, and salaries of 6 employees. The document then provides 6 XQuery examples to extract data from the XML file, such as getting all telephone numbers, names of employees with salaries under 40000, and presenting matching names in HTML. It also includes a sample university.xml file containing department details like head of department (hod) name, budgets, number of faculty and students. Queries are provided to extract the hod name where the consumable budget is 5000, and to order the result by num_faculty.

Uploaded by

utsavkumari
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
44 views3 pages

XML Query

The document contains employee information from an XML file called employee.xml. It includes the names, departments, contact details, and salaries of 6 employees. The document then provides 6 XQuery examples to extract data from the XML file, such as getting all telephone numbers, names of employees with salaries under 40000, and presenting matching names in HTML. It also includes a sample university.xml file containing department details like head of department (hod) name, budgets, number of faculty and students. Queries are provided to extract the hod name where the consumable budget is 5000, and to order the result by num_faculty.

Uploaded by

utsavkumari
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 3

XQUERY

employee.xml
<Employee_Info>
<Employee Employee_Number="109">
<Name>Hanu</Name>
<Department>CSE Department</Department>
<Telephone>03-1452-4567</Telephone>
<Email>[email protected]</Email>
<salary>20000</salary>
</Employee>
<Employee Employee_Number="102">
<Name>Babita Ahuja</Name>
<Department>I.T. Department</Department>
<Telephone>03-6459-98764</Telephone>
<Email>[email protected]</Email>
<salary>30000</salary>
</Employee>
<Employee Employee_Number="103">
<Name>Neelu Choudhary</Name>
<Department>CSE Department</Department>
<Telephone>03-6459-98764</Telephone>
<Email>[email protected]</Email>
<salary>40000</salary>
</Employee>
<Employee Employee_Number="104">
<Name>Nikita Taneja</Name>
<Department>CSE Department</Department>
<Telephone>03-6129-98764</Telephone>
<Email>[email protected]</Email>
<salary>50000</salary>
</Employee>
<Employee Employee_Number="105">
<Name>Ritu Saluja</Name>
<Department>CSE Department</Department>
<Telephone>03-1259-98764</Telephone>
<Email>[email protected]</Email>
<salary>60000</salary>
</Employee>
<Employee Employee_Number="106">
<Name>Jyoti Pruthi</Name>
<Department>IT Department</Department>
<Telephone>01-1159-98764</Telephone>
<Email>[email protected]</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