05 XML
05 XML
10 avril 2024
Lecturer
Dr. HAMDANI M
1 About XML
3 XML Syntax
4 DTD
5 XML Schema
3 XML Syntax
4 DTD
5 XML Schema
3 XML Syntax
4 DTD
5 XML Schema
The terms parent, child, and sibling are used to describe the relation-
ships between elements.
University of Tissemsilt Application Web Development 8 / 39
XML Tree Structure (2)
XML documents are formed as element trees.
An XML tree starts at a root element and branches from the root
to child elements.
All elements can have sub elements (child elements)
<root>
<child>
<subchild>.....</subchild>
</child>
</root>
3 XML Syntax
4 DTD
5 XML Schema
</book>
</library>
3 XML Syntax
4 DTD
5 XML Schema
3 XML Syntax
4 DTD
5 XML Schema
<xs:element name="student">
<xs:complexType>
<xs:sequence>
<xs:element name="firstName" type="xs:string"/>
<xs:element name="birthDate" type="xs:date"/>
<xs:element name="speciality" type="xs:string"/>
<xs:element name="email" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
schema_file = "student.xsd"
xml_file = "students.xml"
try:
validate(schema_file) # Validate the schema
print("XML document is valid!")
except Exception as e:
print("Validation Error:", e)
3 XML Syntax
4 DTD
5 XML Schema
2. XSLT Stylesheet
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<h1>My Book List</h1>
<ul>
<xsl:apply-templates select="books/book" />
</ul>
</body>
</html>
</xsl:template>
<xsl:template match="book">
<li>
<b><xsl:value-of select="title" /></b> by
<i><xsl:value-of select="author" /></i>
</li>
</xsl:template>
</xsl:stylesheet>
Inside this template, it creates the basic HTML structure for the output
document (including an <h1> and a <ul> for the list).
Inside this template, it creates an li element for each book in the list.
It uses xsl :value-of to extract the values of the title and author ele-
ments and inserts them into the HTML output with formatting (bold
for title, italic for author).