xml, dtd: exercisessvoboda/courses/2016... · a7b36xml, ad7b36xml: xml technologies | practical...
TRANSCRIPT
![Page 1: XML, DTD: Exercisessvoboda/courses/2016... · A7B36XML, AD7B36XML: XML Technologies | Practical Classes 1 and 2: XML, DTD: Exercises | 3. and 10. 3. 2017 11 Exercise 10 •Modify](https://reader034.vdocument.in/reader034/viewer/2022042512/5f7235e67406a6356e0b1df2/html5/thumbnails/1.jpg)
http://www.ksi.mff.cuni.cz/~svoboda/courses/2016-2-A7B36XML/
A7B36XML, AD7B36XML: XML Technologies
XML, DTD: Exercises 3. and 10. 3. 2017
Practical Classes 1 and 2:
Jiří Helmich | [email protected] Martin Svoboda | [email protected]
![Page 2: XML, DTD: Exercisessvoboda/courses/2016... · A7B36XML, AD7B36XML: XML Technologies | Practical Classes 1 and 2: XML, DTD: Exercises | 3. and 10. 3. 2017 11 Exercise 10 •Modify](https://reader034.vdocument.in/reader034/viewer/2022042512/5f7235e67406a6356e0b1df2/html5/thumbnails/2.jpg)
A7B36XML, AD7B36XML: XML Technologies | Practical Classes 1 and 2: XML, DTD: Exercises | 3. and 10. 3. 2017 2
Exercise 1
• Create an XML document with the following sample real estate data
Root element real-estate will contain a sequence of sub-elements agencies, owners, properties and flats, all with an empty content
Ensure well-formedness
![Page 3: XML, DTD: Exercisessvoboda/courses/2016... · A7B36XML, AD7B36XML: XML Technologies | Practical Classes 1 and 2: XML, DTD: Exercises | 3. and 10. 3. 2017 11 Exercise 10 •Modify](https://reader034.vdocument.in/reader034/viewer/2022042512/5f7235e67406a6356e0b1df2/html5/thumbnails/3.jpg)
A7B36XML, AD7B36XML: XML Technologies | Practical Classes 1 and 2: XML, DTD: Exercises | 3. and 10. 3. 2017 3
Exercise 2
• Create an internal DTD for the previous XML document
Ensure its validity
Then try to break it
![Page 4: XML, DTD: Exercisessvoboda/courses/2016... · A7B36XML, AD7B36XML: XML Technologies | Practical Classes 1 and 2: XML, DTD: Exercises | 3. and 10. 3. 2017 11 Exercise 10 •Modify](https://reader034.vdocument.in/reader034/viewer/2022042512/5f7235e67406a6356e0b1df2/html5/thumbnails/4.jpg)
A7B36XML, AD7B36XML: XML Technologies | Practical Classes 1 and 2: XML, DTD: Exercises | 3. and 10. 3. 2017 4
Exercise 3
• Move the previous DTD to an external file and validate the XML document again
![Page 5: XML, DTD: Exercisessvoboda/courses/2016... · A7B36XML, AD7B36XML: XML Technologies | Practical Classes 1 and 2: XML, DTD: Exercises | 3. and 10. 3. 2017 11 Exercise 10 •Modify](https://reader034.vdocument.in/reader034/viewer/2022042512/5f7235e67406a6356e0b1df2/html5/thumbnails/5.jpg)
A7B36XML, AD7B36XML: XML Technologies | Practical Classes 1 and 2: XML, DTD: Exercises | 3. and 10. 3. 2017 5
Exercise 4
• Extend the previous DTD such that… Elements agencies, owners, properties and flats can now contain
particular agency, owner, property and flat elements respectively
‒ Agency = name, e-mail, phone
‒ Owner = name
‒ Property = name, description, number of flats, features, owner reference
‒ Flat = name, description, features, property reference
Use attributes for references, otherwise elements
Use only CDATA and #PCDATA for content and values
• Extend the XML document such that it contains 1 sample agency, 1 owner, 1 property, and 2 flats Ensure well-formedness and validity
![Page 6: XML, DTD: Exercisessvoboda/courses/2016... · A7B36XML, AD7B36XML: XML Technologies | Practical Classes 1 and 2: XML, DTD: Exercises | 3. and 10. 3. 2017 11 Exercise 10 •Modify](https://reader034.vdocument.in/reader034/viewer/2022042512/5f7235e67406a6356e0b1df2/html5/thumbnails/6.jpg)
A7B36XML, AD7B36XML: XML Technologies | Practical Classes 1 and 2: XML, DTD: Exercises | 3. and 10. 3. 2017 6
Exercise 5
• Modify both the DTD and XML:
Description of properties…
‒ may now contain a text with references to flats
‒ E.g.: …<flatReference flatName="A1001">…</flatReference>…
Description of flats…
‒ now contains a structured description with an arbitrary, but still well-formed XML fragment
![Page 7: XML, DTD: Exercisessvoboda/courses/2016... · A7B36XML, AD7B36XML: XML Technologies | Practical Classes 1 and 2: XML, DTD: Exercises | 3. and 10. 3. 2017 11 Exercise 10 •Modify](https://reader034.vdocument.in/reader034/viewer/2022042512/5f7235e67406a6356e0b1df2/html5/thumbnails/7.jpg)
A7B36XML, AD7B36XML: XML Technologies | Practical Classes 1 and 2: XML, DTD: Exercises | 3. and 10. 3. 2017 7
Exercise 6
• Extend both the DTD and XML:
Agencies, owners and properties must now have right one address (directly after their name)
Each address consists of:
‒ Street and number
‒ Postal code
‒ State
‒ Country
Respect the order, but note also that country is optional and when missing, postal code must be placed at the end (i.e. after state and not before)
![Page 8: XML, DTD: Exercisessvoboda/courses/2016... · A7B36XML, AD7B36XML: XML Technologies | Practical Classes 1 and 2: XML, DTD: Exercises | 3. and 10. 3. 2017 11 Exercise 10 •Modify](https://reader034.vdocument.in/reader034/viewer/2022042512/5f7235e67406a6356e0b1df2/html5/thumbnails/8.jpg)
A7B36XML, AD7B36XML: XML Technologies | Practical Classes 1 and 2: XML, DTD: Exercises | 3. and 10. 3. 2017 8
Exercise 7
• Modify both the DTD and XML:
Address, e-mail and phone records of agencies may now be specified in an arbitrary order
Ensure that there are at least 2 flats
If features (of properties and flats) are specified, then at least 2 and at most 5 of them are provided
![Page 9: XML, DTD: Exercisessvoboda/courses/2016... · A7B36XML, AD7B36XML: XML Technologies | Practical Classes 1 and 2: XML, DTD: Exercises | 3. and 10. 3. 2017 11 Exercise 10 •Modify](https://reader034.vdocument.in/reader034/viewer/2022042512/5f7235e67406a6356e0b1df2/html5/thumbnails/9.jpg)
A7B36XML, AD7B36XML: XML Technologies | Practical Classes 1 and 2: XML, DTD: Exercises | 3. and 10. 3. 2017 9
Exercise 8
• Extend both the DTD and XML:
Flats can now be associated with internal records
Each record contains…
‒ Date and additional textual information, or
‒ sequence of at lest one nested record
![Page 10: XML, DTD: Exercisessvoboda/courses/2016... · A7B36XML, AD7B36XML: XML Technologies | Practical Classes 1 and 2: XML, DTD: Exercises | 3. and 10. 3. 2017 11 Exercise 10 •Modify](https://reader034.vdocument.in/reader034/viewer/2022042512/5f7235e67406a6356e0b1df2/html5/thumbnails/10.jpg)
A7B36XML, AD7B36XML: XML Technologies | Practical Classes 1 and 2: XML, DTD: Exercises | 3. and 10. 3. 2017 10
Exercise 9
• Modify and extend both the DTD and XML:
Add language attribute to the root element
‒ The value needs to be fixed to EN
Add comfort level attribute to flats
‒ Only A, B, C, D, E or F values are allowed
‒ F is the default value
References to owners of properties are now optional
![Page 11: XML, DTD: Exercisessvoboda/courses/2016... · A7B36XML, AD7B36XML: XML Technologies | Practical Classes 1 and 2: XML, DTD: Exercises | 3. and 10. 3. 2017 11 Exercise 10 •Modify](https://reader034.vdocument.in/reader034/viewer/2022042512/5f7235e67406a6356e0b1df2/html5/thumbnails/11.jpg)
A7B36XML, AD7B36XML: XML Technologies | Practical Classes 1 and 2: XML, DTD: Exercises | 3. and 10. 3. 2017 11
Exercise 10
• Modify and extend both the DTD and XML:
Add attributes with unique artificial identifiers to owners, properties and flats
‒ E.g. o1, o2 in case of owners etc.
Transform all the existing references from names to these new identifiers
Use ID and IDREF data types
• Try to violate the referential integrity
![Page 12: XML, DTD: Exercisessvoboda/courses/2016... · A7B36XML, AD7B36XML: XML Technologies | Practical Classes 1 and 2: XML, DTD: Exercises | 3. and 10. 3. 2017 11 Exercise 10 •Modify](https://reader034.vdocument.in/reader034/viewer/2022042512/5f7235e67406a6356e0b1df2/html5/thumbnails/12.jpg)
A7B36XML, AD7B36XML: XML Technologies | Practical Classes 1 and 2: XML, DTD: Exercises | 3. and 10. 3. 2017 12
Exercise 11
• Extend both the DTD and XML:
Insert the following fragment into a description of a selected flat in a way that it is not interpreted as XML
‒ <span class="btn">Button</span>
‒ Use entities
Declare a new parsed entity for the superscript of 2 and use it as well
‒ Unicode U+00B2 (178)
![Page 13: XML, DTD: Exercisessvoboda/courses/2016... · A7B36XML, AD7B36XML: XML Technologies | Practical Classes 1 and 2: XML, DTD: Exercises | 3. and 10. 3. 2017 11 Exercise 10 •Modify](https://reader034.vdocument.in/reader034/viewer/2022042512/5f7235e67406a6356e0b1df2/html5/thumbnails/13.jpg)
A7B36XML, AD7B36XML: XML Technologies | Practical Classes 1 and 2: XML, DTD: Exercises | 3. and 10. 3. 2017 13
Exercise 12
• Extend the XML document:
Insert the following fragment into a description of one of the flats using a CDATA section:
‒ <span class="btn">Button</span>
Generate a date of one of the flat records using a PHP processing instruction:
‒ echo date("Y-m-d");
Add comments to visually separate individual parts of the document
![Page 14: XML, DTD: Exercisessvoboda/courses/2016... · A7B36XML, AD7B36XML: XML Technologies | Practical Classes 1 and 2: XML, DTD: Exercises | 3. and 10. 3. 2017 11 Exercise 10 •Modify](https://reader034.vdocument.in/reader034/viewer/2022042512/5f7235e67406a6356e0b1df2/html5/thumbnails/14.jpg)
A7B36XML, AD7B36XML: XML Technologies | Practical Classes 1 and 2: XML, DTD: Exercises | 3. and 10. 3. 2017 14
Exercise 13
• Modify the DTD schema:
Using parameter entities and conditional sections, declare 2 modes for the content of owners:
‒ Verbose
• Everything
‒ Standard
• Everything except the description
Activate the standard mode and adjust the XML document appropriately