JSON is not the only way to describe data. XML is an older format that is still used in many systems, and it connects to the idea of strict, valid markup.
What XML Is
XML, Extensible Markup Language, stores and transports data using tags that the author chooses. It describes what the data is, and does not describe how to display it. A student record might use the tags student, name and course. Unlike HTML, XML has no built-in tags.
Definition: XML. Extensible Markup Language, a format that uses custom tags to carry data.
Well-formed XML
A document is well-formed when it follows the basic rules: there is exactly one root element, every tag is closed, tags are properly nested, tag names are case sensitive and attribute values are in quotes. A parser stops with an error on a document that is not well-formed.
Definition: Well-formed XML. XML that follows the basic syntax rules, such as one root element and closed tags.
Valid XML: DTD and XML Schema
A well-formed document may still break the rules of its own design. A DTD, Document Type Definition, lists the allowed elements, their order and their attributes. An XML Schema does the same job, but is itself written in XML, and it can also set data types such as integer and date. A document that follows its DTD or schema is valid.
Table 4.9: Well-formed and valid XML
| Term | Meaning | Checked against |
|---|---|---|
| Well-formed | Follows XML syntax rules | The XML rules |
| Valid | Follows its own design | A DTD or schema |
XSL, XSLT and XHTML
XSL describes how XML is displayed or transformed. XSLT is its transformation language, and it can convert an XML document into HTML or into another form. XHTML is HTML rewritten under XML rules: lowercase tags, every tag closed and quoted attributes. HTML5 relaxed these rules, but the habits of XHTML still lead to clean code.
Example 4.9: A student record and its DTD
<?xml version="1.0"?>
<!DOCTYPE student [
<!ELEMENT student (name, course)>
<!ELEMENT name (#PCDATA)>
<!ELEMENT course (#PCDATA)>
]>
<student id="7">
<name>Asha</name>
<course>BCA</course>
</student>
The root is student. It has the attribute id and two child elements, name and course. The DTD says that student must contain a name followed by a course.
Common mistakes
- Using HTML tag names in XML and expecting them to have a meaning.
- Having two root elements, or leaving a tag unclosed.
- Confusing well-formed with valid, since a well-formed document may still be invalid.
- Using different capitals in the opening and closing tags.
Key takeaways
- XML carries data in author-defined tags, and it does not describe display.
- Well-formed means correct syntax, and valid means following a DTD or schema.
- XML Schema also sets data types, and XSLT transforms XML into other forms.
- XHTML is HTML written under XML rules.
Practice questions
- What is the difference between well-formed and valid XML?
- What does XSLT do?
- How many root elements can an XML document have?
Answers to the practice questions
- Well-formed means it follows XML syntax, and valid means it also follows its DTD or schema.
- It transforms an XML document into HTML or another form.
- Exactly one.
Sources
- Official BCA syllabus (NEP 2025 scheme), Web Application Development, course code 25BCA405DS04, Unit IV
