P:
X M L(unit-2)
HTML (Hypertext Markup Language) has been called the foundation of the World
Wide Web. It provides a standardized way to create Web pages containing formatted
information that can be viewed by global audience through Internet. HTML combined with
HTTP(Hypertext Transfer Protocol) has revolutionized how people can send and receive
information(e-mail). HTML aims at presentation of text like bold, italic or making
headings small or big, but not how it is structured like headings, writing comments etc.
This is where Extensible Markup Language(XML) comes in. Extensible means it is not a
fixed format like HTML. It is designed to enable the use of SGML on the World Wide
Web. XML enables a new style of Web-based data viewing and manipulation applications.
XML is derived from SGML (standard Generalized Markup Language), which was
established in 1986 as an electronic document exchange standard. XML is a subset of
SGML. XML is an open text based markup language that provides structural semantic
information of metadata. Although XML is often called simply a language, strictly
speaking it is a meta language(like SGML). This means, that XML can be used to create
other languages. With XML, we can create new tags of our own and these new tags are
used for structuring data in documents. If we have a database of students, we can have tags
specifying student name, rollno, rank, identification marks or anything we like.
The difference between SGML and XML is that XML is interoperable with both
HTML and SGML. Any valid XML document is valid SGML document. XML does not
replace HTML but works together with it. This interoperability is a kick-starting a new
generation of business and electronic commerce Web applications.
XML 1.0 specification is currently approved by the W3C
Advantages of XML
XML brings power and flexibility to Web-based applications. It provides a number
of benefits to developers and users such as:
• More meaningful searches
• Development of flexible Web applications
• Data integration from sources
• Local computation and manipulation of data
• Multiple views of the data
• Granular updates
Prolog
The beginning statements in a XML document are known as prolog and are
optional. Generally, XML documents should start with a prolog that describes the XML
version, document type and other characteristics of the document. The prolog is
immediately followed by the root tag of the document.
Definition: The part of XML document that is written at the beginning and before
root tag is collectively known as the prolog.
The prolog consists of two optional basic components.
, P:
1.The XML declaration
2.The Document type declaration
1. The XML Declaration
The XML declaration identifies the version of the XML specification to which the
document conforms. The following statement illustrates the XML declaration.
<?xml version=“1.0” ?>
The above XML declaration is optional and must be in lowercase letters only.
2. Document Type Declaration
The XML declaration is immediately followed by Document Type Declaration.
The document declaration must appear following the XML declaration.
<?xml version = “1.0”?> <! - - XML declaration - - >
<!DOCTYPE wildflowers SYSTEM “Wldflr.dtd”> <! - - Document Type
Declaration- - >
This statement tells the XML processor that the document is having the root
element wildflowers and conforms to the rules set in the DTD file named Wldflr.dtd.
SYSTEM means the DTD file is available locally within the system or in LAN. The other
word we can use is PUBLIC and means it is open to public and can be accessed through
Web. After SYSTEM or PUBLIC, the name of the URL containing DTD should be
specified.
XML Syntax Rules
1. XML Documents Must Have a Root Element
2. All XML Elements Must Have a Closing Tag
3. XML Tags are Case Sensitive
4. XML Elements Must be Properly Nested
5. XML Attribute Values Must be Quoted
XML Elements/tags
An XML element is everything from (including) the element's start tag to (including) the
element's end tag.
An element can contain:
1.text
2.attributes
3.other elements
4.or a mix of the above
1st Program: To write a simple XML document without DTD (wellformed)
Aim: to display students in tree order as in Window Explorer.
1. File Name: first.xml
, P:
<?xml version = "1.0"?>
<school>
<student category=”a”>
<name>vaag</name>
<rollno>28</rollno>
<marks>
<english>90</english>
<science>85</science>
<total>175</total>
<rank>first</rank>
</marks>
<residence>LMD COLONY</residence>
</student>
<student category=”a”>
<name>VAAG1</name>
<rollno>25</rollno>
<marks>
<english>50</english>
<science>70</science>
<total>120</total>
<rank>first</rank>
</marks>
<residence>RAMAKRISHNA COLONY</residence>
</student>
</school>
In the above example <school> and <student> have element contents, because they contain
other elements.<student> also has an attribute(category=”a”).<name>,<rollno>,
<residence> have text contents because they contain text.
XML Naming Rules
XML elements must follow these naming rules:
Element names are case-sensitive
Element names must start with a letter or underscore
Element names cannot start with the letters xml (or XML, or Xml, etc)
Element names can contain letters, digits, hyphens, underscores, and periods
Element names cannot contain spaces
Any name can be used; no words are reserved (except xml).
XML Elements are Extensible
XML elements can be extended to carry more information.
Look at the following XML example:
<note>
<to>Tove</to>
<from>Jani</from>
<body>Don't forget me this weekend!</body>
</note>
, P:
Let's imagine that we created an application that extracted the <to>, <from>, and <body>
elements from the XML document to produce this output:
MESSAGE
To: Tove
From: Jani
Don't forget me this weekend!
Imagine that the author of the XML document added some extra information to it:
<note>
<date>2008-01-10</date>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
Should the application break or crash?
No. The application should still be able to find the <to>, <from>, and <body> elements in
the XML document and produce the same output.
This is one of the beauties of XML. It can be extended without breaking applications.
XML Attributes
Additional information regarding the XML elements is provided by the XML attributes
Ex:
<person gender="female">
Note: XML Attributes Must be Quoted
XML Elements vs. Attributes
Ex1:
<person gender="female">
<firstname>sarswathi</firstname>
<lastname>sai</lastname>
</person>
Ex2:
<person>
<gender>female</gender>
<firstname> sarswathi </firstname>
<lastname> sai </lastname>
</person>
In the first example gender is an attribute. In the second, gender is an element. Both
examples provide the same information.No specific rules exist inorder to convey
information regarding the usage of attributes or elements.It is better to avoid usage of
attributes in XML.
X M L(unit-2)
HTML (Hypertext Markup Language) has been called the foundation of the World
Wide Web. It provides a standardized way to create Web pages containing formatted
information that can be viewed by global audience through Internet. HTML combined with
HTTP(Hypertext Transfer Protocol) has revolutionized how people can send and receive
information(e-mail). HTML aims at presentation of text like bold, italic or making
headings small or big, but not how it is structured like headings, writing comments etc.
This is where Extensible Markup Language(XML) comes in. Extensible means it is not a
fixed format like HTML. It is designed to enable the use of SGML on the World Wide
Web. XML enables a new style of Web-based data viewing and manipulation applications.
XML is derived from SGML (standard Generalized Markup Language), which was
established in 1986 as an electronic document exchange standard. XML is a subset of
SGML. XML is an open text based markup language that provides structural semantic
information of metadata. Although XML is often called simply a language, strictly
speaking it is a meta language(like SGML). This means, that XML can be used to create
other languages. With XML, we can create new tags of our own and these new tags are
used for structuring data in documents. If we have a database of students, we can have tags
specifying student name, rollno, rank, identification marks or anything we like.
The difference between SGML and XML is that XML is interoperable with both
HTML and SGML. Any valid XML document is valid SGML document. XML does not
replace HTML but works together with it. This interoperability is a kick-starting a new
generation of business and electronic commerce Web applications.
XML 1.0 specification is currently approved by the W3C
Advantages of XML
XML brings power and flexibility to Web-based applications. It provides a number
of benefits to developers and users such as:
• More meaningful searches
• Development of flexible Web applications
• Data integration from sources
• Local computation and manipulation of data
• Multiple views of the data
• Granular updates
Prolog
The beginning statements in a XML document are known as prolog and are
optional. Generally, XML documents should start with a prolog that describes the XML
version, document type and other characteristics of the document. The prolog is
immediately followed by the root tag of the document.
Definition: The part of XML document that is written at the beginning and before
root tag is collectively known as the prolog.
The prolog consists of two optional basic components.
, P:
1.The XML declaration
2.The Document type declaration
1. The XML Declaration
The XML declaration identifies the version of the XML specification to which the
document conforms. The following statement illustrates the XML declaration.
<?xml version=“1.0” ?>
The above XML declaration is optional and must be in lowercase letters only.
2. Document Type Declaration
The XML declaration is immediately followed by Document Type Declaration.
The document declaration must appear following the XML declaration.
<?xml version = “1.0”?> <! - - XML declaration - - >
<!DOCTYPE wildflowers SYSTEM “Wldflr.dtd”> <! - - Document Type
Declaration- - >
This statement tells the XML processor that the document is having the root
element wildflowers and conforms to the rules set in the DTD file named Wldflr.dtd.
SYSTEM means the DTD file is available locally within the system or in LAN. The other
word we can use is PUBLIC and means it is open to public and can be accessed through
Web. After SYSTEM or PUBLIC, the name of the URL containing DTD should be
specified.
XML Syntax Rules
1. XML Documents Must Have a Root Element
2. All XML Elements Must Have a Closing Tag
3. XML Tags are Case Sensitive
4. XML Elements Must be Properly Nested
5. XML Attribute Values Must be Quoted
XML Elements/tags
An XML element is everything from (including) the element's start tag to (including) the
element's end tag.
An element can contain:
1.text
2.attributes
3.other elements
4.or a mix of the above
1st Program: To write a simple XML document without DTD (wellformed)
Aim: to display students in tree order as in Window Explorer.
1. File Name: first.xml
, P:
<?xml version = "1.0"?>
<school>
<student category=”a”>
<name>vaag</name>
<rollno>28</rollno>
<marks>
<english>90</english>
<science>85</science>
<total>175</total>
<rank>first</rank>
</marks>
<residence>LMD COLONY</residence>
</student>
<student category=”a”>
<name>VAAG1</name>
<rollno>25</rollno>
<marks>
<english>50</english>
<science>70</science>
<total>120</total>
<rank>first</rank>
</marks>
<residence>RAMAKRISHNA COLONY</residence>
</student>
</school>
In the above example <school> and <student> have element contents, because they contain
other elements.<student> also has an attribute(category=”a”).<name>,<rollno>,
<residence> have text contents because they contain text.
XML Naming Rules
XML elements must follow these naming rules:
Element names are case-sensitive
Element names must start with a letter or underscore
Element names cannot start with the letters xml (or XML, or Xml, etc)
Element names can contain letters, digits, hyphens, underscores, and periods
Element names cannot contain spaces
Any name can be used; no words are reserved (except xml).
XML Elements are Extensible
XML elements can be extended to carry more information.
Look at the following XML example:
<note>
<to>Tove</to>
<from>Jani</from>
<body>Don't forget me this weekend!</body>
</note>
, P:
Let's imagine that we created an application that extracted the <to>, <from>, and <body>
elements from the XML document to produce this output:
MESSAGE
To: Tove
From: Jani
Don't forget me this weekend!
Imagine that the author of the XML document added some extra information to it:
<note>
<date>2008-01-10</date>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
Should the application break or crash?
No. The application should still be able to find the <to>, <from>, and <body> elements in
the XML document and produce the same output.
This is one of the beauties of XML. It can be extended without breaking applications.
XML Attributes
Additional information regarding the XML elements is provided by the XML attributes
Ex:
<person gender="female">
Note: XML Attributes Must be Quoted
XML Elements vs. Attributes
Ex1:
<person gender="female">
<firstname>sarswathi</firstname>
<lastname>sai</lastname>
</person>
Ex2:
<person>
<gender>female</gender>
<firstname> sarswathi </firstname>
<lastname> sai </lastname>
</person>
In the first example gender is an attribute. In the second, gender is an element. Both
examples provide the same information.No specific rules exist inorder to convey
information regarding the usage of attributes or elements.It is better to avoid usage of
attributes in XML.