XMLques
XMLques
Sheet
Section 1: XML Exercises
Exercise 1: Creating an XML Document
Create an XML document representing a library system. The document should include the
following details:
Library Name
Books (with Title, Author, Genre, and Year of Publication)
Members (with Member ID, Name, and Join Date)
Example Structure:
<Library>
<LibraryName>City Central Library</LibraryName>
<Books>
<Book>
<Title>The Great Gatsby</Title>
<Author>F. Scott Fitzgerald</Author>
<Genre>Fiction</Genre>
<Year>1925</Year>
</Book>
<!-- Add more books -->
</Books>
<Members>
<Member>
<MemberID>101</MemberID>
<Name>John Doe</Name>
<JoinDate>2023-01-15</JoinDate>
</Member>
<!-- Add more members -->
</Members>
</Library>
Create an XML Schema (XSD) to validate the XML document you created in Exercise 1. The
schema should:
Questions to Answer:
What are the benefits of using an XML Schema?
How does validation improve data integrity?
<Company>
<Employees>
<Employee>
<Name>John White</Name>
<Position>Manager</Position>
<Salary>30000</Salary>
</Employee>
<Employee>
<Name>Ann Beech</Name>
<Position>Assistant</Position>
<Salary>25000</Salary>
</Employee>
</Employees>
</Company>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<h2>Library Books</h2>
<table border="1">
<tr>
<th>Title</th>
<th>Author</th>
</tr>
<xsl:for-each select="Library/Books/Book">
<tr>
<td><xsl:value-of select="Title"/></td>
<td><xsl:value-of select="Author"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
<School>
<Students>
<Student>
<Name>Mary Jane</Name>
<Grade>A</Grade>
</Student>
<Student>
<Name>Peter Parker</Name>
<Grade>B</Grade>
</Student>
</Students>
</School>
Using the XML document from Exercise 7, write XQuery expressions using FLWOR to:
Given the XML document from Exercise 1, use both XPath and XQuery to:
Bonus Challenge:
Research the differences between XML Schema (XSD) and Document Type Definition (DTD).
Create a table comparing their features and provide a brief report on when to use each.