Vous êtes sur la page 1sur 5

CAMOSUN COLLEGE COMPUTER SCIENCE DEPARTMENT COMP 244 TOPICS IN COMPUTING: XML LAB 6 XSD COMPLEX TYPES SUBTYPING

NG AND INTRO TO XPATH DUE: SUNDAY, FEBRUARY 23, 2014, 11:59PM

Theory:
In Lab 5, you sub-typed XSD Simple Types. You added restrictions on some base types either built-in or user-defined. In this lab, you will do some subtyping on Complex Types (what you learned in the XML Schema Slides, Part 4). Sub-types on Complex Types can contain either Simple Content or Complex Content. Simple Content is typically used for adding an attribute to a Complex Type or restricting an attribute or content of Simple Content in another Complex Type. Complex Content is used for extending and restricting Elements and Attributes of Complex Types. Also in Part 4 of the XML Schema Slides, you learned about using xs:include to insert a supporting schema within another primary schema. You will make use of this feature for this lab. Finally, you will install BaseX, a light-weight, high-performance and scalable XML Database engine and XPath/XQuery 3.0 Processor1.

Procedure:
YOU CAN WORK WITH A PARTNER FOR THIS LAB (UP TO TEAMS OF 2 PEOPLE) Part 1 Subtyping Complex Types In Lab 5, you sub-typed the built-in Simple Types that you used to define your schema in Lab 4. In this Lab, you are going to sub-type the Complex Types. Going back to the airplane example, the part of the schema that validates the model of the airplane could look like so:
<xs:element name="model"> <xs:complexType> <xs:sequence> <xs:element name="manufacturer" type="local:manufacturer-type" /> <xs:element name="family" type="xs:string" /> <xs:element name="variant" type="local:model-variant-type" /> <xs:element name="range" type="xs:positiveInteger" /> </xs:sequence> </xs:complexType> </xs:element>

Currently, the Complex Type is anonymous. This can be changed to a user-defined named type and the element would reference that: 1. Change the element declaration to: <xs:element name=model type=local:model-base-type />

From the BaseX home page: http://basex.org/home/

2. Put the sequence into a globally declared named type declaration:


<xs:complexType name=model-base-type> <xs:sequence> <xs:element name="manufacturer" type="local:manufacturer-type" /> <xs:element name="family" type="xs:string" /> <xs:element name="variant" type="local:model-variant-type" /> <xs:element name="range" type="xs:positiveInteger" /> </xs:sequence> </xs:complexType> 3.

Then an extension could be added in a new subtyped Complex Type. Perhaps two elements: one the maximum take-off weight and the other maximum landing weight:
<xs:complexType name=model-type> <xs:complexContent> <xs:extension base=local:model-base-type> <xs:sequence> <xs:element name="max-take-off-weight type=" xs:positiveInteger" /> <xs:element name="max-land-weight" type="xs:positiveInteger" /> </xs:sequence> </xs:extension> </xs:complexContent> </xs:complexType>

4. Finally, the type for model would now need to be changed to the new type: <xs:element name=model type=local:model-type />

The requirements for Part 1 of this lab that you must fulfill are below: On one of your User-defined Simple Types that you made in Lab 5, add a required attribute. Do so by sub-typing. Create a new Complex Type (since it will now have an attribute AND parsed content) and extend the Simple Type. Add an extension to one of your Complex Types, like the example above. This typically involves adding extra elements to an xs:sequence or xs:choice (remember, you cant extend an xs:all). Add a restriction to a different Complex Type. This could be removing an element or attribute, limiting the number of times an element or attribute appears (using minOccurs or maxOccurs) or limiting the type on one of the elements or attributes (using xs:positiveInteger instead of xs:integer for example).

Refer to the slides for XML Schemas Part 4 and refer to the in-class example and solution. Hand in your updated Schema and a screenshot of DOMPrints output of a validated XML instance document that meets the new criteria above. Part 2 Installing BaseX BaseX is a free, open-source XML database. It is also a XPath/XQuery Processor. We will be 2

using this component of the software to run XPath Queries on XDOMs. To install BaseX, follow the below steps: 1. Go to http://basex.org/products/download/all-downloads/ and download BaseX. I HIGHLY recommend the Windows Installer version. This is easiest one to use however as you can see, BaseX is Java based and will run on any OS that supports Java. 2. Run the installer. It will ask you about associating with XQuery and XML files and whether to create a desktop shortcut. You can accept or change these as you wish. 3. It will install several components: the BaseX GUI, BaseX Server, BaseX Client, and BaseX Standalone. The BaseX GUI is the component we will be using. The other components are to do with the Database functionality that we wont be looking at, for now (and only possibly later). 4. Documentation is here: http://docs.basex.org/wiki/Main_Page There is also a downloadable PDF on that page. Part 3 Running your first XPath Queries Start up the BaseX GUI. The top left window is the Project Explorer, the top right an Editor, the bottom left contains Query results and finally the bottom right contains Query Information. To start using the BaseX GUI, you need to load an XML Instance Document into it that will be stored as a database. You can then run XQueries on it using XPath: 1. Go up to Database -> Open & Manage or hit the Open & Manage folder icon. 2. A prompt will come up telling you no database was found and if you would like to create a new one. Hit Yes. 3. Download the xml-sample-doc.xml file from D2L. This is the same XML file from Part 2 of the XPath slides. Now select it as the Input file in BaseX. The database name automatically gets filled in with the XML files name. Leave the Input format as XML. Dont worry about the Parsing and Indexes tabs:

4. Hit OK. The BaseX GUI should now show a Visualization Map of the XDOM in a new window in the top right, the result of creating the dB in the bottom right window, and the entire XML document in the bottom left window. 3

5. Close the Project Explorer and Editor windows. We wont be using those, so lets get them out of the way! Go up to View and uncheck where it says Editor. That should get rid of both windows. 6. Now you can run XQueries! In the Text Box beside where it says Find, enter the following: //b1 That is the XPath expression to select element node b1. Hit enter or hit the execute query button (the green play button on the right). Three things will happen. The Visualization Map will show the result of the query by highlighting the selected nodes in Red. The bottom right window gives some information about the query, like how long it took to execute. Finally, the bottom left window shows the result of the query, in regular XML:

In this case, you should see the b1 node. Note that it is listing its contents: all its descendants because they are inside the node. Try executing this XPath expression: //b1/descendant-or-self::* Notice the difference in the results. It lists b1 again (self) with all its contents but it also lists each node separately since each of them make up the element set returned by this XPath expression:

For Part 3 of this lab, create the proper XPath expression for each of the following: 1. an XPath expression that selects the parent of b200. 2. an XPath expression that selects all the ancestors of c010. 3. an XPath expression that selects only the children of a0. 4. an XPath expression that selects a0 and its descendants. 5. an XPath expression that selects the preceding sibling(s) of the parent of a010. Submit a screenshot of BaseX after executing each of the above queries. Ensure the entire result of the Query appears in the bottom left window. You can submit each image separately or put together in a .docx or .pdf file. Ensure they are big enough to be readable!!

Submission Instructions:
Submit to the lab 6 dropbox the following seven items (DO NOT ZIP): Screenshot of output from DOMPrint of your XML Document showing that it validates against the new Schema. Ensure the entire contents of your XML Instance Document are clearly visible in your screenshot. Your new XML Schema file. Five BaseX Screenshots for each of the queries listed in Part 3. You can either submit these files separately OR paste into a single .docx or .pdf document. If working in a team of two, only one of you needs to submit (make it clear who your partner is). 5

Vous aimerez peut-être aussi