XML Markup Languages – Appendix 9
Project
Course: [Write course name here]
Student: [Your Name]
Date: [Insert Date]
1. Introduction
Extensible Markup Language (XML) is a markup language designed to structure and
transport data. Unlike HTML, which focuses on presentation, XML focuses on data meaning
and organization. It is widely used in web services, APIs, configuration files, and enterprise
applications. In this project, we demonstrate how XML, XSLT, and SQL/XML work together
to represent, transform, and query structured data.
2. HTML vs XML
HTML and XML are both markup languages but serve different purposes:
- HTML: Presentation-focused, defines how content looks.
- XML: Data-focused, defines what the content means.
HTML Example (App9.1):
<html>
<head><title>Web page EXAMPLE</title></head>
<body>
<p>This is an example of an HTML web page.</p>
<b><p>This part is in bold font.</p></b>
<i><p>This part is in italic font.</p></i>
</body>
</html>
3. XML Example – Inspectors Data
File: [Link]
<?xml version="1.0" ?>
<?xml-stylesheet type="text/xsl" href="[Link]"?>
<buildinginspectors>
<inspector>
<insid>I11</insid>
<insname>Jane</insname>
<department>Electrical</department>
</inspector>
<inspector>
<insid>I22</insid>
<insname>Niko</insname>
<department>Plumbing</department>
</inspector>
<inspector>
<insid>I33</insid>
<insname>Mick</insname>
<department>Construction</department>
</inspector>
<inspector>
<insid>I44</insid>
<insname>Ana</insname>
<department>Fire Safety</department>
</inspector>
</buildinginspectors>
👉 Insert Screenshot Here: Raw XML view in browser.
4. XSLT Transformations
XSLT allows transforming XML into formatted HTML.
a) Simple Text Output – [Link]
<?xml version="1.0" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="[Link]
<xsl:template match="/">
<html>
<head><title>Web page XML EXAMPLE1</title></head>
<body>
<b>Building Inspectors</b>
<xsl:for-each select="buildinginspectors/inspector">
<p>Inspector ID: <xsl:value-of select="insid"/></p>
<p>Inspector Name: <xsl:value-of select="insname"/></p>
<p>Department: <xsl:value-of select="department"/></p>
</xsl:for-each>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
👉 Insert Screenshot Here: Output of [Link] (list format).
b) Table Output – [Link]
<?xml version="1.0" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="[Link]
<xsl:template match="/">
<html>
<head><title>Web page XML EXAMPLE2</title></head>
<body>
<b>Building Inspectors</b>
<table border="1">
<tr bgcolor="#D3D3D3">
<th>Inspector ID</th>
<th>Inspector Name</th>
<th>Department</th>
</tr>
<xsl:for-each select="buildinginspectors/inspector">
<tr>
<td><xsl:value-of select="insid"/></td>
<td><xsl:value-of select="insname"/></td>
<td><xsl:value-of select="department"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
👉 Insert Screenshot Here: Output of [Link] (table format).
5. SQL/XML Queries in Jupyter
You can demonstrate SQL/XML in either MySQL (simulated XML) or SQL Server (native
XML).
a) MySQL with Jupyter
import [Link]
import pandas as pd
# Connect to MySQL
conn = [Link](
host="localhost",
user="root",
password="your_password",
database="testdb"
)
cursor = [Link]()
# Create table
[Link]("DROP TABLE IF EXISTS Inspector;")
[Link]("""
CREATE TABLE Inspector (
insid VARCHAR(10) PRIMARY KEY,
insname VARCHAR(50),
department VARCHAR(50)
)
""")
# Insert dummy data
[Link](
"INSERT INTO Inspector (insid, insname, department) VALUES (%s, %s, %s)",
[('I11', 'Jane', 'Electrical'),
('I22', 'Niko', 'Plumbing'),
('I33', 'Mick', 'Construction'),
('I44', 'Ana', 'Fire Safety')]
)
[Link]()
# Query A
df = pd.read_sql("SELECT insid, insname, department FROM Inspector;", conn)
display(df) # 👉 Screenshot this
# Query AX (simulated XML)
df_xml = pd.read_sql("""
SELECT CONCAT(
'<inspector><insid>', insid, '</insid>',
'<insname>', insname, '</insname>',
'<department>', department, '</department></inspector>'
) AS xml_output FROM Inspector;
""", conn)
display(df_xml) # 👉 Screenshot this
b) SQL Server with Jupyter
import pyodbc
import pandas as pd
conn = [Link](
"DRIVER={ODBC Driver 17 for SQL Server};"
"SERVER=localhost;"
"DATABASE=testdb;"
"UID=sa;"
"PWD=your_password;"
)
cursor = [Link]()
[Link]("IF OBJECT_ID('Inspector', 'U') IS NOT NULL DROP TABLE Inspector;")
[Link]("""
CREATE TABLE Inspector (
insid VARCHAR(10) PRIMARY KEY,
insname VARCHAR(50),
department VARCHAR(50)
)
""")
[Link]("INSERT INTO Inspector VALUES ('I11','Jane','Electrical'),
('I22','Niko','Plumbing'),('I33','Mick','Construction'),('I44','Ana','Fire Safety')")
[Link]()
df = pd.read_sql("SELECT insid, insname, department FROM Inspector;", conn)
display(df) # 👉 Screenshot this
query_xml = """
SELECT insid, insname, department
FROM Inspector
FOR XML PATH('inspector'), ROOT('buildinginspectors');
"""
[Link](query_xml)
rows = [Link]()
for row in rows:
print(row[0]) # 👉 Screenshot this XML output
6. XPath and XQuery Overview
XPath and XQuery are powerful for querying XML:
- XPath: Selects parts of XML. Example: /buildinginspectors/inspector/insname retrieves all
names.
- XQuery: Performs complex queries. Example:
for $i in doc("[Link]")/buildinginspectors/inspector
return <result>{$i/insid} - {$i/insname} ({$i/department})</result>
7. How to Run and Test Live Examples
1. Save XML and XSL files in one folder.
2. Open [Link] in Firefox to apply XSL.
3. Run SQL queries in Jupyter connected to MySQL or SQL Server.
4. Take screenshots of results and paste them into this document.
8. Screenshots (To Be Added)
- Screenshot 1: Raw XML in browser.
- Screenshot 2: [Link] output.
- Screenshot 3: [Link] output.
- Screenshot 4: Query A output.
- Screenshot 5: Query AX output.
9. Key Learnings
1. XML structures and organizes data.
2. XSLT can transform XML into readable HTML.
3. SQL/XML integrates relational databases with XML.
4. XPath and XQuery provide querying capabilities for XML.
5. XML remains relevant in modern data integration even with JSON's rise.
10. Conclusion
This project demonstrated XML basics, XSLT transformations, SQL/XML queries, and XML
querying approaches. By combining structured XML with transformation and database
integration, we can store, transform, and query data flexibly. The practical examples and
screenshots illustrate how XML bridges data storage and presentation. This structured
workflow reflects real-world enterprise data management scenarios.