Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
29 views

Module 5 Notes

The document discusses XML including its introduction, syntax, document type definitions, namespaces, schemas, displaying raw and styled XML documents. It defines XML, compares it to HTML, lists its features and advantages. It also discusses the difference between XML and XHTML.

Uploaded by

Likith SR
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views

Module 5 Notes

The document discusses XML including its introduction, syntax, document type definitions, namespaces, schemas, displaying raw and styled XML documents. It defines XML, compares it to HTML, lists its features and advantages. It also discusses the difference between XML and XHTML.

Uploaded by

Likith SR
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 22

Web Programming(20CSI43) Module-5

Nagarjuna College of Engineering and Technology,


Bengaluru
Autonomous College Under VTU
Department of CSE (Data Science)

WEB PROGRAMMING (IC)


20CSI43

MODULE 5

XML

By
Prof. Likhith S R
Assistant. Professor
Dept. of CSE(DS), NCET

Dept. of CSE(Data Science), NCET 1 2021-22


Web Programming(20CSI43) Module-5

Module - V
XML: Introduction, Syntax, Document Type Definitions, Namespaces, XML Schemas,
Displaying Raw XML Documents, Displaying XML Documents with CSS.
What is xml
• Xml (eXtensible Markup Language) is a mark up language.
• XML is designed to store and transport data.
• Xml was released in late 90’s. it was created to provide an easy to use and store self
describing data.
• XML became a W3C Recommendation on February 10, 1998.
• XML is not a replacement for HTML.
• XML is designed to be self-descriptive.
• XML is designed to carry data, not to display data.
• XML tags are not predefined. You must define your own tags.
• XML is platform independent and language independent.
XML Does Not DO Anything
• Maybe it is a little hard to understand, but XML does not DO anything.
• This note is a note to Tove from Jani, stored as XML:
The XML above is quite self-descriptive:
• It has sender information
• It has receiver information
• It has a heading
• It has a message body
But still, the XML above does not DO anything. XML is just information wrapped in tags.
Someone must write a piece of software to send, receive, store, or display it:

<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>

Dept. of CSE(Data Science), NCET 2 2021-22


Web Programming(20CSI43) Module-5

The Difference Between XML and HTML

No. HTML XML

1) HTML is used to display data and XML is a software and hardware


focuses on how data looks. independent tool used to transport and
store data. It focuses on what data is.

2) HTML is a markup language itself. XML provides a framework to define


markup languages.

3) HTML is not case sensitive. XML is case sensitive.

4) HTML is a presentation language. XML is neither a presentation language nor


a programming language.

5) HTML has its own predefined tags. You can define tags according to your
need.

6) In HTML, it is not necessary to use a XML makes it mandatory to use a closing


closing tag for few tags. tag.

7) HTML is static because it is used to XML is dynamic because it is used to


display data. transport data.

8) HTML does not preserve whitespaces. XML preserve whitespaces.

Features and Advantages of XML


• XML is widely used in the era of web development. It is also used to simplify data
storage and data sharing.
• The main features or advantages of XML are given below.
1) XML separates data from HTML
• If you need to display dynamic data in your HTML document, it will take a lot of
work to edit the HTML each time the data changes.
• With XML, data can be stored in separate XML files. This way you can focus on
using HTML/CSS for display and layout, and be sure that changes in the underlying
data will not require any changes to the HTML.
• With a few lines of JavaScript code, you can read an external XML file and update
the data content of your web page.
2) XML simplifies data sharing

Dept. of CSE(Data Science), NCET 3 2021-22


Web Programming(20CSI43) Module-5

• In the real world, computer systems and databases contain data in incompatible
formats.
• XML data is stored in plain text format. This provides a software- and hardware-
independent way of storing data.
• This makes it much easier to create data that can be shared by different applications.
3) XML simplifies data transport
• One of the most time-consuming challenges for developers is to exchange data
between incompatible systems over the Internet.
• Exchanging data as XML greatly reduces this complexity, since the data can be read
by different incompatible applications.
4) XML simplifies Platform change
• Upgrading to new systems (hardware or software platforms), is always time
consuming. Large amounts of data must be converted and incompatible data is often
lost.
• XML data is stored in text format. This makes it easier to expand or upgrade to new
operating systems, new applications, or new browsers, without losing data.
5) XML increases data availability
• Different applications can access your data, not only in HTML pages, but also from
XML data sources.
• With XML, your data can be available to all kinds of "reading machines" (Handheld
computers, voice machines, news feeds, etc), and make it more available for blind
people, or people with other disabilities.
6) XML can be used to create new internet languages
A lot of new Internet languages are created with XML.
Here are some examples:
• XHTML
• WSDL for describing available web services
• WAP and WML as markup languages for handheld devices
• RSS languages for news feeds
• RDF and OWL for describing resources and ontology
• SMIL for describing multimedia for the web

Dept. of CSE(Data Science), NCET 4 2021-22


Web Programming(20CSI43) Module-5

Difference between XML and XHTML


What is XML?
• XML is a markup language that is used to transfer data and text between driver
hardware, operating systems and applications with little human intervention.
• XML provides tags, attributes and element structures that can be used to provide
context information.
• This context information can be used to decode the meaning of the content.
What is XHTML?
• XHTML can be seen as a cleaner version of HTML, which is also stricter than
HTML.
• XHTML is also a W3C recommendation (recommended in January, 2000) and it is a
combination of HTML and XML.
• In XHTML, everything needs to be marked up correctly unlike in HTML.
• This would make sure that well formatted documents will be produced.

Parameters of
XML XHTML
Comparison

XML represents Extensive Markup XHTML represents Extensible


Full-Form
Language. Hypertext Markup Language.

XML refers to a simple text-based


format that is used for representing
XHTML refers to a cross between
structured information like data,
Definition XML and HTML that is used for
transactions, configuration,
transiting from HTML to XML.
documents, invoices, books, and so
on.

XML was first published in 1998. XHTML was initially released in


Release
2000.

XML has a hierarchical tree- XHTML is developed based on three


Structure shaped structure which is called main components- declaration, head,
XML tree. and body.

Dept. of CSE(Data Science), NCET 5 2021-22


Web Programming(20CSI43) Module-5

XHTML comprises three versions-


Components XML is composed of Unicode. XHTML Transitional, XHTML 1.0
Frameset, and XHTML 1.0 Strict.

1. XML is considered to be the most useful and popular Markup language, whereas
XHTML is less popular or less important compared to XML on basis of the usage.
2. XML refers to a simple text-based format that is used for representing structured
information like data, transactions, configuration, documents, invoices, books, and
so on. On the other hand, XHTML refers to a cross between XML and HTML that is
used for transiting from HTML to XML.
3. XML was first published in 1998 but XHTML was initially released in 2000.
4. XML has a hierarchical tree-shaped structure which is called XML tree. XHTML is
developed based on three main components- declaration, head, and body.
5. XML is composed of Unicode. XHTML comprises three versions- XHTML
Transitional, XHTML 1.0 Frameset, and XHTML 1.0 Strict.
XML Syntax and Rules
• The syntax rules of XML are very simple and logical. The rules are easy to learn,
and easy to use.
• XML Documents Must Have a Root Element
• XML documents must contain one root element that is the parent of all other
elements:

<root>
<child>
<subchild>.....</subchild>
</child>
</root>
The XML Prolog
• This line is called the XML prolog: <?xml version="1.0" encoding="UTF-8"?>
• The XML prolog is optional. If it exists, it must come first in the document.
• XML documents can contain international characters, like Norwegian øæå or French
êèé.
• To avoid errors, you should specify the encoding used, or save your XML files as
UTF-8.
• UTF-8 is the default character encoding for XML documents.

Dept. of CSE(Data Science), NCET 6 2021-22


Web Programming(20CSI43) Module-5

<?xml version="1.0" encoding="UTF-8"?>


<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>

• In this example <note> is the root element


• All XML Elements Must Have a Closing Tag
• In XML, it is illegal to omit the closing tag. All elements must have a closing tag:

<p>This is a paragraph.</p>
<br />

XML Tags are Case Sensitive


• XML tags are case sensitive. The tag <Letter> is different from the tag <letter>.
• Opening and closing tags must be written with the same case:

<message>This is correct</message>

• "Opening and closing tags" are often referred to as "Start and end tags". Use
whatever you prefer. It is exactly the same thing.
XML Elements Must be Properly Nested
• In HTML, you might see improperly nested elements:

<b><i>This text is bold and italic</b></i>

• In XML, all elements must be properly nested within each other:

<b><i>This text is bold and italic</i></b>

• In the example above, "Properly nested" simply means that since the <i> element is
opened inside the <b> element, it must be closed inside the <b> element.
XML Tree Structure
• An XML document has a self descriptive structure.
• It forms a tree structure which is referred as an XML tree.
• The tree structure makes easy to describe an XML document.
• A tree structure contains root element (as parent), child element and so on.
• It is very easy to traverse all succeeding branches and sub-branches and leaf nodes
starting from the root.
Dept. of CSE(Data Science), NCET 7 2021-22
Web Programming(20CSI43) Module-5

<?xml version="1.0"?>
<college>
<student>
<firstname>Tamanna</firstname>
<lastname>Bhatia</lastname>
<contact>09990449935</contact>
<email>tammanabhatia@abc.com</e mail>
<address>
<city>Ghaziabad</city>
<state>Uttar Pradesh</state>
<pin>201007</pin>
</address>
</student>
</college>

• In the above example, first line is the XML declaration. It defines the XML version
1.0. Next line shows the root element (college) of the document. Inside that there is
one more element (student). Student element contains five branches named
<firstname>, <lastname>, <contact>, <Email> and <address>.
• <address> branch contains 3 sub-branches named <city>, <state> and <pin>.

Dept. of CSE(Data Science), NCET 8 2021-22


Web Programming(20CSI43) Module-5

XML Tree Rules


• These rules are used to figure out the relationship of the elements. It shows if an
element is a child or a parent of the other element.
• Descendants: If element A is contained by element B, then A is known as descendant
of B. In the above example "College" is the root element and all the other elements
are the descendants of "College".
• Ancestors: The containing element which contains other elements is called
"Ancestor" of other element. In the above example Root element (College) is
ancestor of all other elements.
XML DTD
• An XML document with correct syntax is called "Well Formed".
• An XML document validated against a DTD is both "Well Formed" and "Valid“
• 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>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>

• The purpose of a DTD is to define the structure and the legal elements and attributes
of an XML document:
The DTD above is interpreted like this:
• !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"

Dept. of CSE(Data Science), NCET 9 2021-22


Web Programming(20CSI43) Module-5

Note.dtd:
<!DOCTYPE note
[
<!ELEMENT note (to,from,heading,body)>
<!ELEMENT to (#PCDATA)>
<!ELEMENT from (#PCDATA)>
<!ELEMENT heading (#PCDATA)>
<!ELEMENT body (#PCDATA)>
]>
Ex2:
<?xml version = "1.0" encoding = "UTF-8" standalone = "no" ?>
<!DOCTYPE address SYSTEM "address.dtd">
<address>
<name>Tanmay Patil</name>
<company>TutorialsPoint</company>
<phone>(011) 123-4567</phone>
</address>

DTD
<!ELEMENT address (name,company,phone)>
<!ELEMENT name (#PCDATA)>
<!ELEMENT company (#PCDATA)>
<!ELEMENT phone (#PCDATA)>

Dept. of CSE(Data Science), NCET 10 2021-22


Web Programming(20CSI43) Module-5

XML Schema
• An XML Schema describes the structure of an XML document, just like a DTD.
• An XML document with correct syntax is called "Well Formed".
• An XML document validated against an XML Schema is both "Well Formed" and
"Valid".
• XML Schema is an XML-based alternative to DTD:

<xs:element name="note">

<xs:complexType>
<xs:sequence>
<xs:element name="to" type="xs:string"/>
<xs:element name="from" type="xs:string"/>
<xs:element name="heading" type="xs:string"/>
<xs:element name="body" type="xs:string"/>
</xs:sequence>
</xs:complexType>

</xs:element>

The Schema above is interpreted like this:


• <xs:element name="note"> defines the element called "note"
• <xs:complexType> the "note" element is a complex type
• <xs:sequence> the complex type is a sequence of elements
• <xs:element name="to" type="xs:string"> the element "to" is of type string (text)
• <xs:element name="from" type="xs:string"> the element "from" is of type string
• <xs:element name="heading" type="xs:string"> the element "heading" is of type
string
• <xs:element name="body" type="xs:string"> the element "body" is of type string
XSD Data types

String Data Type

 String data types are used for values that contains character strings.

 The string data type can contain characters, line feeds, carriage returns, and tab
characters.

 The following is an example of a string declaration in a schema:

Dept. of CSE(Data Science), NCET 11 2021-22


Web Programming(20CSI43) Module-5

<xs:element name="customer" type="xs:string"/>

 An element in your document might look like this:

<customer>John Smith</customer>

Integer Data Type

 The integer data type is used to specify a numeric value without a fractional component.

 The following is an example of an integer declaration in a schema:

<xs:element name="price" type="xs:integer"/>

 An element in your document might look like this:

<price>999</price>

Decimal Data Type

 The decimal data type is used to specify a numeric value.

 The following is an example of a decimal declaration in a schema:

<xs:element name="price" type="xs:decimal"/>

 An element in your document might look like this:

<price>999.50</price>
Boolean
The xsd:boolean data type accepts two values, true and false, but depending on whether it
is on input or output data, these values representatio ns can change.
On input (on queries), boolean values can be:

 String literals without quotation marks. For


example, oslc.where=crtv:boolValue=true
 Quoted strings. For example, oslc.where=crtv:boolValue="false"
 Quoted numeric values. For example, oslc.where=crtv:boolValue="1"

<xsd:element name="Active" type="xs:boolean" />

Dept. of CSE(Data Science), NCET 12 2021-22


Web Programming(20CSI43) Module-5

XML Namespaces
• XML Namespaces provide a method to avoid element name conflicts.
• In XML, element names are defined by the developer. This often results in a conflict
when trying to mix XML documents from different XML applications.
• This XML carries HTML table information:

<table>
<tr>
<td>Apples</td>
<td>Bananas</td>
</tr>
</table>

• This XML carries information about a table (a piece of furniture):

<table>
<name>African Coffee Table</name>
<width>80</width>
<length>120</length>
</table>

• If these XML fragments were added together, there would be a name conflict. Both
contain a <table> element, but the elements have different content and meaning.
• A user or an XML application will not know how to handle these differences.
Solving the Name Conflict Using a Prefix
• Name conflicts in XML can easily be avoided using a name prefix.
• This XML carries information about an HTML table, and a piece of furniture
• In the example above, there will be no conflict because the two <table> elements
have different names.

<h:table>
<h:tr>
<h:td>Apples</h:td>
<h:td>Bananas</h:td>
</h:tr>
</h:table>

<f:table>
<f:name>African Coffee Table</f:name>
<f:width>80</f:width>
<f:length>120</f:length>
</f:table>

Dept. of CSE(Data Science), NCET 13 2021-22


Web Programming(20CSI43) Module-5

XML Namespaces - The xmlns Attribute


• When using prefixes in XML, a namespace for the prefix must be defined.
• The namespace can be defined by an xmlns attribute in the start tag of an element.
• The namespace declaration has the following syntax. xmlns:prefix="URI".

<root>

<h:table xmlns:h="http://www.w3.org/TR/html4/">
<h:tr>
<h:td>Apples</h:td>
<h:td>Bananas</h:td>
</h:tr>
</h:table>

<f:table xmlns:f="https://www.w3schools.com/furniture">
<f:name>African Coffee Table</f:name>
<f:width>80</f:width>
<f:length>120</f:length>
</f:table>

</root>
• In the example above:
• The xmlns attribute in the first <table> element gives the h: prefix a qualified
namespace.
• The xmlns attribute in the second <table> element gives the f: prefix a qualified
namespace.
• When a namespace is defined for an element, all child elements with the same prefix
are associated with the same namespace.
• Namespaces can also be declared in the XML root element:

<root xmlns:h="http://www.w3.org/TR/html4/"
xmlns:f="https://www.w3schools.com/furniture">
</root>

• Note: The namespace URI is not used by the parser to look up information.
• The purpose of using an URI is to give the namespace a unique name.
• However, companies often use the namespace as a pointer to a web page containing
namespace information.

Dept. of CSE(Data Science), NCET 14 2021-22


Web Programming(20CSI43) Module-5

XML Example
• XML documents create a hierarchical structure looks like a tree so it is known as
XML Tree that starts at "the root" and branches to "the leaves".
Example of XML Document
• XML documents uses a self-describing and simple syntax:

<?xml version="1.0" encoding="ISO-8859-1"?>


<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
• The first line is the XML declaration. It defines the XML version (1.0) and the
encoding used (ISO-8859-1 = Latin-1/West European character set).
• The next line describes the root element of the document (like saying: "this
document is a note"): <note>
• The next 4 lines describe 4 child elements of the root (to, from, heading, and body).
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
• And finally the last line defines the end of the root element.
</note>
• XML documents must contain a root element. This element is "the parent" of all
other elements.
• The elements in an XML document form a document tree. The tree starts at the root
and branches to the lowest level of the tree.
• All elements can have sub elements (child elements).

<root>
<child>
<subchild>.....</subchild>
</child>
</root>

• The terms parent, child, and sibling are used to describe the relationships between
elements. Parent elements have children. Children on the same level are called
siblings (brothers or sisters).
• All elements can have text content and attributes (just like in HTML).

Dept. of CSE(Data Science), NCET 15 2021-22


Web Programming(20CSI43) Module-5

Ex1

<bookstore>
<book category="COOKING">
<title lang="en">Everyday Italian</title>
<author>Giada De Laurentiis</author>
<year>2005</year>
<price>30.00</price>
</book>
<book category="CHILDREN">
<title lang="en">Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>
<book category="WEB">
<title lang="en">Learning XML</title>
<author>Erik T. Ray</author>
<year>2003</year>
<price>39.95</price>
</book>
</bookstore>

• The root element in the example is <bookstore>. All elements in the document are
contained within <bookstore>.
• The <book> element has 4 children: <title>,< author>, <year> and <price>.

Displaying XML
• Raw XML files can be viewed in all major browsers.
• Don't expect XML files to be displayed as HTML pages.
Viewing XML Files
<?xml version="1.0" encoding="UTF-8"?>
- <note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
• Most browsers will display an XML document with color-coded elements.
• Often a plus (+) or minus sign (-) to the left of the elements can be clicked to expand
or collapse the element structure.

Dept. of CSE(Data Science), NCET 16 2021-22


Web Programming(20CSI43) Module-5

• To view raw XML source, try to select "View Page Source" or "View Source" from
the browser menu.
Viewing an Invalid XML File
• If an erroneous XML file is opened, some browsers will report the error, and some
will display it, or display it incorrectly.

<?xml version="1.0" encoding="UTF-8"?>


- <note>
<to>Tove</to>
<From>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>

CSS in XML
Purpose of CSS in XML
• CSS (Cascading Style Sheets) can be used to add style and display information to an
XML document. It can format the whole XML document.
How to link XML file with CSS
• To link XML files with CSS, you should use the following syntax:

<?xml-stylesheet type="text/css" href="cssemployee.css"?>

cssemployee.css

employee
{
background-color: pink;
}
firstname,lastname,email
{
font-size:25px;
display:block;
color: blue;
margin- left: 50px;
}

employee.dtd
<!ELEMENT employee (firstname,lastname,email)>
<!ELEMENT firstname (#PCDATA)>
<!ELEMENT lastname (#PCDATA)>
<!ELEMENT email (#PCDATA)>

Dept. of CSE(Data Science), NCET 17 2021-22


Web Programming(20CSI43) Module-5

employee.xml
<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="cssemployee.css"?>
<!DOCTYPE employee SYSTEM "employee.dtd">
<employee>
<firstname>vimal</firstname>
<lastname>jaiswal</lastname>
<email>vimal@javatpoint.com</email>
</employee>

Ex2
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="Rule.css"?>
<books>
<heading>Welcome To GeeksforGeeks </heading>
<book>
<title>Title -: Web Programming</title>
<author>Author -: Chrisbates</author>
<publisher>Publisher -: Wiley</publis her>
<edition>Edition -: 3</edition>
<price> Price -: 300</price>
</book>
<book>
<title>Title -: Internet world-wide-web</title>
<author>Author -: Ditel</author>
<publisher>Publisher -: Pearson</publisher>
<edition>Edition -: 3</edition>
<price>Price -: 400</price>
</book>
<book>
<title>Title -: Computer Networks</title>
<author>Author -: Foruouzan</author>
<publisher>Publisher -: Mc Graw Hill</publisher>
<edition>Edition -: 5</edition>

Dept. of CSE(Data Science), NCET 18 2021-22


Web Programming(20CSI43) Module-5

<price>Price -: 700</price>
</book>
<book>
<title>Title -: DBMS Concepts</title>
<author>Author -: Navath</author>
<publisher>Publisher -: Oxford</publisher>
<edition>Edition -: 5</edition>
<price>Price -: 600</price>
</book>
<book>
<title>Title -: Linux Programming</title>
<author>Author -: Subhitab Das</author>
<publisher>Publisher -: Oxford</publisher>
<edition>Edition -: 8</edition>
<price>Price -: 300</price>
</book>
</books>

Rule.css
books {
color: white;
background-color : gray;
width: 100%;
}
heading {
color: green;
font-size : 40px;
background-color : powderblue;
}
heading, title, author, publisher, edition, price {
display : block;
}
title {
font-size : 25px;

Dept. of CSE(Data Science), NCET 19 2021-22


Web Programming(20CSI43) Module-5

font-weight : bold;
}
• You need two files: The XML file, and a CSS file. In your XML document, you
need to add one line of code. This one line of code tells the processor to display the
XML using styles from the external style sheet.
1. Create an XML file with the following content and save it:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>


<?xml-stylesheet type="text/css" href="tutorials.css"?>
<tutorials>
<tutorial>
<name>XML Tutorial</name>
<url>https://www.quackit.com/xml/tutorial</url>
</tutorial>
<tutorial>
<name>HTML Tutorial</name>
<url>https://www.quackit.com/html/tutorial</url>
</tutorial>
</tutorials>

• In order to style our XML document (which contains the 4


elements tutorials, tutorial, name and url), we can simply add those elements to our
style sheet, followed by the styles we want to be applied to that element. If we don't
need to style an element, we can omit it from the style sheet
2. Create a file with the following content and save it as tutorials.css into the same directory
as the XML file.

tutorials {
margin:10px;
background-color:#ccff00;
font-family:verdana,helvetica,sans-serif;
}
name {
display:block;

Dept. of CSE(Data Science), NCET 20 2021-22


Web Programming(20CSI43) Module-5

font-weight:bold;
}
url {
display:block;
color:#636363;
font-size:small;
font-style:italic;
}

Ex3
<car_catalog>
<car>
<year> 1997 </year>
<make> &c; </make>
<model> Impala </model>
<color> Light blue </color>
<engine>
<number_of_cylinders> 8 cylinder </number_of_cylinders>
<fuel_system> multi-port fuel injected </fuel_system>
</engine>
<number_of_doors> 4 door </number_of_doors>
<transmission_type> 4 speed automatic </transmission_type>
<accessories radio = "yes" air_conditioning = "yes" power_windows = "yes"
power_steering = "yes" power_brakes = "yes" />
</car>
<car_catalog>

DTD
<!ELEMENT car_catalog >
<!ELEMENT car (year, make, model, color, engine, number_of_doors, transmission_type,
accessories)>
<!ELEMENT make (#PCDATA)>
<!ELEMENT model (#PCDATA)>
<!ELEMENT year (#PCDATA)>

Dept. of CSE(Data Science), NCET 21 2021-22


Web Programming(20CSI43) Module-5

<!ELEMENT color (#PCDATA)>


<!ELEMENT engine (number_of_cylinders, fuel_system)>
<!ELEMENT number_of_doors (#PCDATA)>
<!ELEMENT transmission_type (#PCDATA)>
<!ELEMENT accessories (#PCDATA)>
<!ELEMENT number_of_cylinders (#PCDATA)>
<!ELEMENT fuel_system (#PCDATA)>

How Can XML be Used?

 XML is used in many aspects of web development.

 XML is often used to separate data from presentation.

 XML Separates Data from Presentation

 XML does not carry any information about how to be displayed.

 The same XML data can be used in many different presentation scenarios.

 Because of this, with XML, there is a full separation between data and presentation.

 XML is Often a Complement to HTML

 In many HTML applications, XML is used to store or transport data, while HTML is
used to format and display the same data.

 XML Separates Data from HTML

 When displaying data in HTML, you should not have to edit the HTML file when
the data changes.

 With XML, the data can be stored in separate XML files.

 With a few lines of JavaScript code, you can read an XML file and update the data
content of any HTML page.

Dept. of CSE(Data Science), NCET 22 2021-22

You might also like