Question

In: Computer Science

Consider the following XML file: <root> <students> <element> <ID>100345</ID> <Nationality>USA</Nationality> <Program>ICT</Program> <age>23</age> <name>John</name> </element

  1. Consider the following XML file:

<root>

<students>

<element>

<ID>100345</ID>

<Nationality>USA</Nationality>

<Program>ICT</Program>

<age>23</age>

<name>John</name>

</element>

<element>

<ID>100876</ID>

<Nationality>MALAYSIA</Nationality>

<Program>CS</Program>

<age>28</age>

<name>Awang</name>

</element>

<element>

<ID>100257</ID>

<Nationality>AUSTRALIA</Nationality>

<age>25</age>

<name>Alex</name>

</element>

</students>

</root

Write an XQUERY to display the information for all students who are not Malaysians or older than 25.

Solutions

Expert Solution

Xquery is like sql with respect to xml and database respetively

It is used for querying xml data and is built on xpath expressions

it comes under w3c recommendation and is supported by all major databases

It is executed step by step as

finding/ then extracting elements and its attributes from xml based documents, can be used to generate summary reports , extract content from web services, etc

For following xml file let the name be students.xml

To open this file we use doc() function

as doc("students.xml")

now to navigate through xml elements we use path expressions

doc("students.xml")/root/students/element

will navigate you through xml to element names user defined tag

now there are also option for predicates like selective retreival of elements

example doc("students.xml")/root/students/element[age<25]

for student with age less than 25

we can also use where for this conditional retreival

also there is option of

Now for given query in question "Write an XQUERY to display the information for all students who are not Malaysians or older than 25"

it is like select query with fllowing syntax format

FLWOR

For Let Where OrderBY and Return

here we do need let and order by

to return all

for $x in doc("students.xml")/root/students/element
where ($x/@Nationality!="Malaysians" and $x/@age<25)
return $x

to return id:

for $x in doc("students.xml")/root/students/element where ($x/@Nationality!="Malaysians" and $x/@age<25) return data($x/@Id)

Hope you are able to understand concept


Related Solutions

3.1. Create an XML schema to validate the following XML file. <?xml version="1.0" encoding="utf-8"?> <root> <whats>Everything</whats>...
3.1. Create an XML schema to validate the following XML file. <?xml version="1.0" encoding="utf-8"?> <root> <whats>Everything</whats> <up>Is</up> <doc>Fine</doc> </root> Schema starter: <xsd:schema xmlns:xsd=""> <xsd:element name="root" type="rootType" /> <xsd:complexType name="rootType">     <xsd:sequence>       <xsd:element name="" type="" minOccurs="1" />       <xsd:element name="” type="" minOccurs="1" />       <xsd:element name="" type="" minOccurs="1" />     </xsd:sequence> </xsd:complexType> </xsd:schema> 3.2. Use your schema to validate the XML file.                     3.2.1. You can use Visual Studio or online utilities to apply the schema to the XML file....
Write a Java program for a restaurant with the following features: ◦ Customer: Name, Surname, ID...
Write a Java program for a restaurant with the following features: ◦ Customer: Name, Surname, ID (incremental ID by 1 for each new customer), Email, Phone, Address. ◦ Service: ID (incremental ID by1 for each group),CustomerID, Priority (High, Medium, Low, Other), ResolutionTimeFrame (Measured in Man hours), AssignedUser, Status(resolved or not), Fee. ◦ User (simple user of system): ID, Name, Surname, Username and Password (insert from code five fixed users), Address , PhoneNumber ◦ Manager: Name, Surname, Username and Password (insert...
Please consider FIRST 6 Character from your name and LAST 2 digits of your students ID....
Please consider FIRST 6 Character from your name and LAST 2 digits of your students ID. Calculate the checksum for the above text. The text needs to be divided into 2-byte (16-bit) words. Also check that the data is reached without any alteration using your checksum. [ the text is MajedA08]
Consider the following relation AIRLINE TABLE Flight Date Flight ID Origin Destination Captain ID Captain Name...
Consider the following relation AIRLINE TABLE Flight Date Flight ID Origin Destination Captain ID Captain Name Number of Passengers on the Flight April 10 111 Chicago L.A. 111 Tracy 110 April 10 222 L.A. Phoenix 222 Matt 105 April 12 111 Chicago L.A. 444 Tim 98 April 12 333 L.A. N.Y. 111 Tracy 75 April 12 444 L.A. N.Y. 333 Pat 110 April 12 555 L.A. Dallas 444 Tim 111 April 12 222 L.A. Phoenix 555 Pat 107 Some of...
Write a python program that does the following: Prompt for a file name of text words....
Write a python program that does the following: Prompt for a file name of text words. Words can be on many lines with multiple words per line. Read the file and convert the words to a list. Call a function you created called list_to_once_words(), that takes a list as an argument and returns a list that contains only words that occurred once in the file. Print the results of the function with an appropriate description. Think about everything you must...
Consider the following class: class Person {         String name;         int age;        ...
Consider the following class: class Person {         String name;         int age;         Person(String name, int age){                this.name = name;                this.age = age;         } } Write a java program with two classes “Teacher” and “Student” that inherit the above class “Person”. Each class has three components: extra variable, constructor, and a method to print the student or the teacher info. The output may look like the following (Hint: you may need to use “super”...
Write a c++ program that does the following, read temperatures from a file name temp.txt into...
Write a c++ program that does the following, read temperatures from a file name temp.txt into an array, and after reading all the temperatures, output the following information: the average temperature, the minimum temperature, and the total number of temperatures read. Thank you!
Consider the following school choice problem: there are four students (George, John, Thomas, and Quincy) and...
Consider the following school choice problem: there are four students (George, John, Thomas, and Quincy) and three schools (Washington, Adams, and Madison). Each school has a capacity of one student. The students' preference lists are as follows: George: Washington, Adams, George, Madison John: Madison, Adams, Washington, John Thomas: Adams, Madison, Thomas, Washington Quincy: Washington, Adams, Madison, Quincy The schools' priority rankings are as follows: Washington: John, Quincy, Thomas, George Adams: John, George, Thomas, Quincy Madison: George, Thomas, John, Quincy What...
Consider the following data. Boardgames ID name price manuf_id 3234 Monopoly 60 HB 2244 Settlers of...
Consider the following data. Boardgames ID name price manuf_id 3234 Monopoly 60 HB 2244 Settlers of Catan 45 MF 2389 Catan: Seafarers 20 MF 4211 Carcassonne 55 VG 4383 Citadels 35 HB 4450 Pandemic 55 VG Manufacturer ID name founded HB Hasbro 1997 MF Mayfair Games 1982 VG Ventura Games 2005 Answer the following: Write the SQL DDL statements to create the tables. Include primary and foreign keys.
Consider the following relational database schema:             employee(employee-name, employee-id, street, e-city)             works(employee-
Consider the following relational database schema:             employee(employee-name, employee-id, street, e-city)             works(employee-id, company-id, salary)             company(company-name, company-id, c-city)             manages(employee-id, manager-id) Specify the following queries on this database schema using the relational operators we discussed in class. Write your answers on a separate sheet of paper in the order that they are specified below. Retrieve the name and address of employees who work for First Bank Corporation. Retrieve the name, street address, and city of residence of all employees...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT