XML: Assignments

Các khóa học qua video:
Python SQL Server PHP C# Lập trình C Java HTML5-CSS3-JavaScript
Học trên YouTube <76K/tháng. Đăng ký Hội viên
Viết nhanh hơn - Học tốt hơn
Giải phóng thời gian, khai phóng năng lực

Bài tập -1:

Cho file XSD như sau:

<?xml version='1.0' encoding='UTF-8' ?>
<!-- was: <?xml version="1.0"?> -->
<xs:schema version="1.0"
           xmlns:xs="http://www.w3.org/2001/XMLSchema"
           targetNamespace="define_XML_for_Student.xxx.kkk_2_s"
           xmlns="define_XML_for_Student.xxx.kkk_2_s"
           elementFormDefault="qualified">
  <xs:element name="Students">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="Student" type="Student_Type"/>
        <!--Phần tử Name="Student" có kiểu là gì, Nó tham chiếu tới phần tử nào  -->
      </xs:sequence>
    </xs:complexType>
  </xs:element>
  <xs:complexType name="Student_Type" maxOccurs="100">
    <xs:sequence>
      <xs:element name="name" type="xs:string"/>
      <xs:element name="email" type="xs:string"/>
      <xs:element name="class" type="xs:string"/>
      <xs:element name="age" type="xs:integer"/>
      <xs:element name="mark" type="xs:decimal"/>
      <xs:element name="range" type="xs:positiveInteger"/>
    </xs:sequence>
  </xs:complexType>

</xs:schema>

Hãy viết 1 file xml  từ file cấu trúc trên.
Phần tử <xs:element name= "Student" type="Student_Type" /> trong file trên có kiểu gì và nó tham chiếu tới phần tử nào.

Bài tập 0:

Cho file XML như sau:

<?xml version="1.0" encoding="utf-8"?>
<bangdiem>
  <tenbang>Bang diem mon hoc Vat ly</tenbang>
  <hocsinh>
    <stt>1</stt>
    <mahocsinh>HS0001</mahocsinh>
    <hoten>Nguyen Ngoc Anh</hoten>
    <diemheso>
      <heso1>8</heso1>
      <heso2>8</heso2>
    </diemheso>
    <diemTBKT>8.0</diemTBKT>
    <diemthi>8</diemthi>
    <diemTBMH>8.0</diemTBMH>
  </hocsinh>
  <hocsinh>
    <stt>2</stt>
    <mahocsinh>HS0002</mahocsinh>
    <hoten>Dang Ba Nam</hoten>
    <diemheso>
      <heso1>8</heso1>
      <heso2>9</heso2>
    </diemheso>
    <diemTBKT>8.7</diemTBKT>
    <diemthi>8</diemthi>
    <diemTBMH>8.5</diemTBMH>
  </hocsinh>
  <hocsinh>
    <stt>3</stt>
    <mahocsinh>HS0003</mahocsinh>
    <hoten>Le Duc Tu</hoten>
    <diemheso>
      <heso1>7</heso1>
      <heso2>6</heso2>
    </diemheso>
    <diemTBKT>6.3</diemTBKT>
    <diemthi>9</diemthi>
    <diemTBMH>7.2</diemTBMH>
  </hocsinh>
  <hocsinh>
    <stt>4</stt>
    <mahocsinh>HS0004</mahocsinh>
    <hoten>Mac Van Vien</hoten>
    <diemheso>
      <heso1>7</heso1>
      <heso2>7</heso2>
    </diemheso>
    <diemTBKT>7.0</diemTBKT>
    <diemthi>8</diemthi>
    <diemTBMH>7.3</diemTBMH>
  </hocsinh>
  <hocsinh>
    <stt>5</stt>
    <mahocsinh>HS0005</mahocsinh>
    <hoten>Vu Dinh Toan</hoten>
    <diemheso>
      <heso1>9</heso1>
      <heso2>7</heso2>
    </diemheso>
    <diemTBKT>8.0</diemTBKT>
    <diemthi>8</diemthi>
    <diemTBMH>8.0</diemTBMH>
  </hocsinh>
  <hocsinh>
    <stt>6</stt>
    <mahocsinh>HS0006</mahocsinh>
    <hoten>Tran Ba Minh</hoten>
    <diemheso>
      <heso1>9</heso1>
      <heso2>10</heso2>
    </diemheso>
    <diemTBKT>9.7</diemTBKT>
    <diemthi>10</diemthi>
    <diemTBMH>9.8</diemTBMH>
  </hocsinh>
  <hocsinh>
    <stt>7</stt>
    <mahocsinh>HS0007</mahocsinh>
    <hoten>Ngo Dinh Tung</hoten>
    <diemheso>
      <heso1>8</heso1>
      <heso2>9</heso2>
    </diemheso>
    <diemTBKT>8.7</diemTBKT>
    <diemthi>8</diemthi>
    <diemTBMH>8.5</diemTBMH>
  </hocsinh>
  <hocsinh>
    <stt>8</stt>
    <mahocsinh>HS0008</mahocsinh>
    <hoten>Do Huu Nam</hoten>
    <diemheso>
      <heso1>7</heso1>
      <heso2>7</heso2>
    </diemheso>
    <diemTBKT>7.0</diemTBKT>
    <diemthi>9</diemthi>
    <diemTBMH>7.7</diemTBMH>
  </hocsinh>
</bangdiem>

Hãy sử dụng XPath để thực hiện các yêu cầu sau:

1. Hãy tìm đến phần tử <hocsinh> có id=1

2. Hãy tìm đến phần tử <diemTBKT> có giá trị 7.7

3. Hãy lấy tất cả các phần tử con của phần tử <hocsinh>

4. Hãy lấy tất cả các phần tử con, cháu, chắt, ... của phần tử <hocsinh>

5. Hãy lấy những phần tử con của phần tử <hocsinh> mà tên phần tử có chứa 'M'

6. Hãy lấy những phần tử <diemTBMH> có chứa giá trị >=8

7. Hãy lấy những phần tử cùng cấp với phần tử <heso1>

8. Hãy lấy phần tử cấp trên của phần tử <heso1>

9. Hãy lấy tên của học sinh có mã = HS0001.

Bài tập 1

Assume that data for a book catalogue is available. An XML document for the book catalogue with the following elements: name, author, pages, price, and table of contents are to be created. The price element should also specify whether the book is accompanied with a CD or DVD or both.

Create an XML document for the above mentioned catalogue displaying data for about 10 books.

Bài tập 2

Global Express is USA’s leading integrated air express carrier and premium logistics-services provider. They have the most extensive domestic network covering over 20 locations.

Every office of theirs has to maintain a record of the letters dispatched on a dayto-day basis. These records are stored in hard copies which make them prone to damage or loss of data. To overcome this possibility, the company has decided to store the information in computers and the data is to be transferred using XML.

Create an XML file called “Order.xml” using the following element names. The specifications are as follows:

  • Invoice
  • Order: (Should have an order number attribute)
    • Customer Name
    • Address
    • Order id
    • Total Price
  • Cod:
    • Shipping Address
    • Shipping method (air or ground)
    • Shipping total
  • Account: (State if the account is active or not. The default should be active.)
    • Customer ID
    • Invoice period
  • Shipping info
    • Ship date
    • Billing Address (This element should be optional)
  • Description
    • Description should be one of the product

Keeping into considerations that there are five regional offices and five different set of data is to be merged at the Head office, duplication of data is a huge possibility. For example, Customer Name in New York can match a customer name in a Chicago. To differentiate the data when it is merged, use namespaces to declare elements. Use entity declarations wherever necessary in the XML document.

Bài tập 3

Local Courier Service Simulation

The local courier service XYZ has branches all over the country. Every region has one regional office that coordinates with the branches in that region. Couriers from the branches are collected and sent to the regional office for sorting and dispatch. Similarly, incoming couriers are sorted at the regional office and sent to the branches.

Every regional office has to maintain a record of the couriers it receives from the branches and of couriers it sends to the branches. Similarly, it needs to maintain records of couriers it sends to other regional offices and receives from other regional offices.

The officials no longer wish to transfer these records as hard copy, which makes it prone to so many possibilities of being damaged or corrupted. They have decided to employ data operators who will feed the information into computers and transfer the data using XML.

Now, the foreseen problem is multiple data operators entering similar data using XML. To resolve the inconsistency that could occur due to operators developing their own tags officials have requested for standardization of the tags to be used. Based on these existing conditions, write a DTD for the above problem. Once the DTD is finalized, test the DTD with fake data. Test both internal and external DOCTYPE declarations.

Make sure tags for addresses are adequate and capable enough to hold any form of address data (Hint: Some addresses have villas while some buildings and apartment number. Look for all possible kinds of addresses and then create the element). The format for how the data will be structured too is open-ended but should be optimal for the above purpose.

(Hint: Make use of the different element declarations. The DTD should take care of information such as branch/regional details, courier details (from and to details), date of receipt of couriers or dispatch of couriers, transportation/shipping details, and so on)

Bài tập 4

An XML file will be used to represent data collected from an online sales Web site. This site sells different kinds of office supplies. Create an XML file that captures the following information:

  • Item Name - examples include paper, clips, rubber bands, pens, and so on.
  • Item Inventory ID - examples include “F12333”, “Z55553”, and so on - restrictions are that the Inventory ID must begin with a letter followed by 5 digits.
  • Item Unit Price - examples include 4.553, 22.33, and so on - must be a double and no less than 1.00.
  • Count in Stock - whole number no less than 0.
  • Stock Bin - this is where the item is located in the stock room - examples include “B786”, “B345”, and so on. - Restrictions are that this must be the letter B followed by three digits.

Requires:

1. Create a Schema file that clearly defines the tags, their elements, data types and implements the restrictions indicated.

2. Create an XML file that represents this data. Use some sample data. Make sure the XML file is well formed.

3. Make sure the Schema file works with the XML file.

Bài tập 5

University Result Simulation

A university desires to display the exam results of its students for all semesters using XML and CSS. The results should be displayed in the figure.

Assignment 5

At the top of the screen, the name of the university should be displayed in white on black background with a border. Then on the next line(s) the address of the university should be displayed in the same manner except that the border need not be so prominent.

The results should be displayed in the following manner. First the Semester number should be displayed in white over a black background. Next, a student’s name should follow in white over grey background. The students name should follow by a block of subject names and the student’s grades in those subjects. All the students, for the respective semester, should be represented in the following manner. The next semester’s details should follow the first one and so on.

Create the XML and CSS document for the same. Simulate data for about fifteen students (three semesters – five students each).

Bài tập 6

Real estate scenario

A local software company Navigator Ltd. deals with the maintenance of data about locations and finance of different showrooms. The company collects the information about the various branches of big showrooms and stores it in its database.

The information includes the number of branches, the amount the branch has to pay as rent, the amount of money that the branch has taken as a loan, the number of people working in that branch and so on.

Every showroom has to register these details in a database. Since it is highly impossible to maintain a record of each and every branch in a country, the IT hub of the showroom decide to outsource it to this software company.

There is a sudden audit in the showroom and the data abstractors of the software company were made to give the following details on an urgent basis:

  • Divide the number of people according to the batches that have joined.
  • The rent that each individual branch pays to their respective landlord.
  • The daily allowance given to the people in all the branches according to the seniority.

Now, prepare a report and display the output in XML using XSL as the style sheet. After the transformation is done, display the records of each section separately. As these results are to be shown to the auditors directly, ensure that proper and clear formatting is done.

Ensure that the data is displayed in a complete formal manner.

Note: Make use of <xsl:template>, <xsl:select>, <xsl:value-of>, <xsl:foreach>, <xsl:sort>.

Bài tập 7

Alveira Technologies, a business process outsourcing firm based in San Jose, was storing details of its employees in XML format. Suddenly the management decided to migrate all its data to HTML format. An application needs to be created that will design and implement an XSLT stylesheet to transform the XML content to HTML format. Make use of XPath and XSLT to achieve the same. 

» Tiếp: Solution Test Theory
« Trước: Test Theory
Các khóa học qua video:
Python SQL Server PHP C# Lập trình C Java HTML5-CSS3-JavaScript
Học trên YouTube <76K/tháng. Đăng ký Hội viên
Viết nhanh hơn - Học tốt hơn
Giải phóng thời gian, khai phóng năng lực
Copied !!!