0% found this document useful (0 votes)
15 views

E Tensible Arkup Anguage

The document discusses XML, including its purpose as a markup language for structured data exchange, comparisons to HTML, XML syntax and structure, well-formed XML rules, document type definitions to define valid XML documents, and when to use and not use DTDs.

Uploaded by

ohioprincess13
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

E Tensible Arkup Anguage

The document discusses XML, including its purpose as a markup language for structured data exchange, comparisons to HTML, XML syntax and structure, well-formed XML rules, document type definitions to define valid XML documents, and when to use and not use DTDs.

Uploaded by

ohioprincess13
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

eXtensible Markup Language (XML)

Outline
• Introduction
• Comparison between XML and HTML
• XML Syntax
What is XML?
• eXtensible Markup Language
• Markup language for documents containing structured information
• XML was designed to store and transport data. XML is platform-
independent and language-neutral.
• It's widely used for data exchange between different systems.
• Commonly used in web services, configuration files, and data
storage.
Comparisons
XML HTML

• Extensible set of tags • Fixed set of tags


• Content orientated • Presentation oriented
• Standard Data infrastructure • No data validation capabilities
• Allows multiple output forms • Single presentation
Syntax of XML
<food>
<name>Belgian Waffles</name>
<price>100</price>
<description>
Two of our famous Belgian Waffles with plenty of
real maple syrup
</description>
<calories>650</calories>
</food>
Well-Formed XML
• For an XML document to be well-formed, it must adhere to certain
rules:
• Must have a single root element.
• All tags must be properly nested.
• All tags must be closed.
• Attribute values must be quoted.
<library>
<book id="1">...</book>
<book id="2">...</book>
<book id="3">...</book>
</library>
XML Data Model: Example
<BOOKS>
<book id=“123” loc=“library”>
BOOKS
<author>Hull</author> book
<title>California</title> loc=“library” article
<year> 1995 </year> ref
123 555
</book>
<article id=“555” ref=“123”>
author year author title
<author>Su</author>
<title> Purdue</title> title
</article>
</BOOKS> Hull 1995 Su Purdue
California
Document Type Definitions (DTD)

• DTD stands for Document Type Definition.


• A DTD defines the structure and the legal elements and attributes
of an XML document.
• A "Valid" XML document is "Well Formed", as well as it conforms to
the rules of a DTD.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE note SYSTEM "Note.dtd">
<note>
<to>Ram</to>
<from>Shyam</from>
<heading>Holi</heading>
<body>Don’t forget that holi is this weekend</body>
</note>
Document Type Definitions (DTD)

• The purpose of a DTD is to define the structure and the legal


elements and attributes of an XML document.
Note.dtd
<!DOCTYPE note
[
<!ELEMENT note (to,from,heading,body)>
<!ELEMENT to (#PCDATA)>
<!ELEMENT from (#PCDATA)>
<!ELEMENT heading (#PCDATA)>
<!ELEMENT body (#PCDATA)>
]>
Document Type Definitions (DTD)

• !DOCTYPE note - Defines that the root element of the document is


note
• !ELEMENT note - Defines that the note element must contain the
elements: "to, from, heading, body"
• !ELEMENT to - Defines the to element to be of type "#PCDATA"
• !ELEMENT from - Defines the from element to be of type "#PCDATA"
• !ELEMENT heading - Defines the heading element to be of type
"#PCDATA"
• !ELEMENT body - Defines the body element to be of type "#PCDATA"
When to Use a DTD?
• With a DTD, independent groups of people can agree to use a
standard DTD for interchanging data.
• With a DTD, you can verify that the data you receive from the outside
world is valid.
• You can also use a DTD to verify your own data.
When not to Use a DTD?
• XML does not require a DTD.
• When you are experimenting with XML, or when you are working with
small XML files, creating DTDs may be a waste of time.
• If you develop applications, wait until the specification is stable
before you add a DTD. Otherwise, your software might stop working
because of validation errors.

You might also like