XML代写: Practical Week 3.  XML Schema and Validation

Practical Week 3.  XML Schema and Validation

Overview

  • By completing this practical exercise you will be able to:
  • Define constraints in a XML Schema file,
  • Modify an XML Schema file, and
  • Perform conformation check.

 

Submission instruction for external students

(Internal student show your work in the practical class)

You submit a word document to include the changes you made in each step.

 

Tasks

  1. Download the files for this practical.
  2. Practice on XML Schema
  • Using EditiX, edit the Schema file xsd in the following way:
    1. Constrain the element <MemberID> to be a string of 5 characters starting with M and followed by 4 digits, e.g. “M1235”. There is an example in the lecture slides.
    2. Make <MemberID> in <GAMEPLAYER> a keyref referring to the <MEMBER> element key. This should be added at the level right ‘above’ the <GAMEPLAYER> element.

Note:

The selection path defines the range to which the constraint applies, and the field paths defines what are expected to be unique within the range. Your selection path must be valid in the context of the constraint.

 

  • An XML Schema file is also an XML document. You can check the syntax correctness of the constraints that you added. In EditIX you check by pressing the document icon with a green tick in the icon bar.  If it is not valid, correct the errors and try again. Note that when the checking comes out correct, it just means that the code that you added to the schema file has no syntax errors. It does not mean that it is semantically correct.

 

  1. Validate the XML document file xml against the updated schema file getfit.xsd. The validation should fail with many errors and one of them must be about keyref. Otherwise, your constraints were not added to the right spot. If this is the case, you need to go back to fix your constraints in the schema file getfit.xsd until the validation of getfit.xml against getfit.xsd fails. You then fix the document until it conforms to the schema file.

 

  1. Add a definition for the Game element to the xsd file under the GFN_DB element (at the same level as GAMEPLAYER). The Game element contains child elements of TeamName1, TeamName2, Date, Venue, and Score. All the child elements are compulsory. Team names must be valid (you need a key for Team and two keyrefs for the Game element).

 

  1. Add a Match instance to the getfit.xml and validate.