Objective

XML Schema

Equipment

Computer with Visual Studio

Procedure(s)

XML Schema

1. Launch the Visual Studio and click on File > New > File menu item.

2.Choose XML File in the dialog box and click open. An editor tab with name ending in [Design] will appear. You are displayed few options to create/edit schema. Click on "Use the XML Editor to view and edit the underlying XML schema file".

3.Save the file as wonders.xsd in working directory.

4.Review the XML schema file. A root level xs:schema tag is already created. Review the various attributes in the tag.

5.Add following code inside the xs:schema tags:

< xs:element name="wonder">
< xs:complexType>
< xs:sequence>
< xs:element name="name">
< xs:complexType>
< xs:simpleContent>
< xs:extension base="xs:string">
< xs:attribute name="language" type="xs:string"/>
< /xs:extension>
< /xs:simpleContent>
< /xs:complexType>
< /xs:element>
< xs:element name="location" type="xs:string"/>
< xs:element name="height" type="xs:string"/>
< /xs:sequence>
< /xs:complexType>
< /xs:element>

Notes: The xs:element with name wonders defines our root level xml element. All other tags from our XML file will be defined as children of this tag. With xs:complexType tag, we are indicating that this element is a complex type element which can contains other elements and/or attributes. With xs:sequence tag, we are indicating that all enclosing tags should appear in the given sequence and can have any number of occurrences (including 0 i.e. may be missing). The name element is a complexType since we want to add language attribute to it. The other two elements - location and height are simple type since they do not have any attributes or children.

6.Define an element name < history> within the < wonder> element sequence.

7.Define < year_built> and < year_destroyed> elements of type integer.

8.Define the < how_destroyed> element as type string. Set the default to fire.

9.We can declare custom types outside the root tag. These custom types can be then used to create multiple elements. Add the following code as second child of xs:schema tag

< xs:simpleType name="story_type">
< xs:restriction base="xs:string">
< xs:length value="1024"/>
< /xs:restriction>
< /xs:simpleType>

10.Define element named < story> of story_type as child of the < history> element.

11.Define a simple type named year_type that is a whole number and has a minimum value of 0 and a maximum value of 5000.

12.Modify the < year_built> and < year_destroyed> elements to be of type year_type.

13.In the wonders.xsd [Design] tab, click on "Use the XML Schema Explorer to browse your entire schema as a tree". In the Schema Explorer window expand and review your schema.

Exercise(s):

1.Based on the wonders.xml, complete your schema wonders.xsd.

2.Convert year_type to a complex type. It should be defined as a positive integer that has an attribute named era of type string.

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.