Date post: | 07-Apr-2015 |
Category: |
Documents |
Upload: | aryaaccent |
View: | 110 times |
Download: | 0 times |
eXXtensible MMarkup LLanguage (XML)
By:
Anupam Kumar
Outline of Presentation Introduction Comparison between XML and HTML Building Blocks of XML. XML Elements XML Tree XML Data Island DTD Summary.
What is XML?
XML stands for eXtensible Markup Language Markup language for documents containing
structured information XML is a markup language much like HTML XML was designed to carry data, not to
display data XML tags are not predefined. You must
define your own tags XML is designed to be self-descriptive.
XML…. Based on Standard Generalized Markup
Language (SGML) Version 1.0 introduced by World Wide Web
Consortium (W3C) in 1998 Bridge for data exchange on
the Web
Comparisons
Extensible set of tags XML was designed to
transport and store data, with focus on what data is.
Standard Data infrastructure
Allows multiple output forms
White-space is Preserved in XML.
Fixed set of tags HTML was designed
to display data, with focus on how data looks
No data validation capabilities
Single presentation Not in HTML.
XML HTML
Building blocks for XMLElements : are the main building blocks
of both XML and HTML documents .Attributes : provide extra information
about elements .PCDATA : Parsed character data, will be
examined by parser for entities & markup.CDATA : Character data is used about
text data that should not be parsed by the XML parser.
XML Elements XML document must contain a root element. This
element is parent of all other elements. An XML element is made up of a start tag, an end tag,
and data in between. Example: <director> Matthew Dunn </director> Children on the same level are called siblings (brothers
or sisters). XML tags are case-sensitive: <CITY> <City> <city> XML can abbreviate empty elements, for example: <married> </married> can be abbreviated to <married/>
XML Elements(Cont’d)Entity References
There are 5 predefined entity references in XML:
XML Elements (cont’d)
All elements must have an end tag. All elements must be cleanly nested
(overlapping elements are not allowed).
XML AttributesAn attribute is a name-value pair
separated by an equal sign (=) and attribute value must be in “ ”.
Example:
<City ZIP=“94608”> Hyderabad </City>Attributes are used to attach additional,
secondary information to an element.
Use of Elements vs. Attributes
Data can be stored in child elements or in attributes.
Example:-
<person sex="male"> <firstname>Anupam</firstname> <lastname>Kumar</lastname></person>
This is same as
Use of Elements vs. Attributes(Cont’d)
<person> <sex>female</sex> <firstname>Anna</firstname> <lastname>Smith</lastname></person>
Avoid using attributes?Some of the problems with attributes are:
attributes cannot contain multiple values (child elements can).
attributes are not easily expandable (for future changes).
attributes cannot describe structures (child elements can).
attributes are more difficult to manipulate by program code.
attribute values are not easy to test against a DTD.
XML Tree
XML Tree(Cont’d)
<bookstore> <book category=“programming"> <title lang ="en">Complete Reference
To Java</title> <author> Balagurswamy</author> <year>2005</year> <price>250.00</price> </book>
XML Tree(Cont’d)
<book category="CHILDREN"> <title lang="en">Harry Potter</title> <author>J K. Rowling</author> <year>2005</year> <price>600.00</price> </book>
XML Tree(Cont’d)
<book category="WEB"> <title lang ="en">Learning XML</title> <author>Erik T. Ray</author> <year>2003</year> <price>500.00</price> </book></bookstore>
XML Data Islands
A data island is an XML document that exists within an HTML page.
The <XML> element marks the beginning of the data island, and its ID attribute provides a name that you can use to reference the data island.
XML Data Islands (Cont’d) Example:
<XML ID=“XMLID”>
<customer>
<name> Anupam Kumar</name>
<custID> 1500712</custID>
</customer>
</XML>
XML Validation
XML with correct syntax is "Well Formed" XML.
XML validated against a DTD is "Valid" XML.
A "Valid" XML document is a "Well Formed" XML document, which also conforms to the rules of a Document Type Definition (DTD)
Document Type Definitions (DTD)
An XML document may have an optional DTD.
DTD serves as grammar for the underlying XML document, and it is part of XML language.
DTD has the form: <!DOCTYPE name [mark up declaration]>
DTD (cont’d)
Consider an XML document:
<db>
<person gender =“male”>
<name>Anupam</name>
<age>24</age>
<email>[email protected]</email>
</person>
<person>………</person>
</db>
DTD (cont’d)DTD for it might be:
<!DOCTYPE db [ <!ELEMENT db (person*)> <!ELEMENT person (name, age, email)> <!ELEMENT name (#PCDATA)> <!ELEMENT age (#PCDATA)> <!ELEMENT email (#PCDATA)><!ATTLIST person gender CDATA
#REQUIRED> ]>
DTD(Cont’d)
A DTD can be declared inline inside an XML document, or as an external reference. Internal DTD Declaration
External DTD Declaration
DTD(Cont’d) Internal DTD Declaration
If the DTD is declared inside the XML file, it should be wrapped in a DOCTYPE definition with the following syntax:
<!DOCTYPE root-element [element-declarations]>
Example:-
DTD(Cont’d) <?xml version="1.0"?>
<!DOCTYPE note [<!ELEMENT note (to,from,heading,body)><!ELEMENT to (#PCDATA)><!ELEMENT from (#PCDATA)><!ELEMENT heading (#PCDATA)><!ELEMENT body (#PCDATA)>]><note><to>Hari</to><from>Anupam</from><heading>Reminder</heading><body>Don't forget me this weekend</body></note>
DTD(Cont’d)External DTD Declaration
If the DTD is declared in an external file, it should be wrapped in a DOCTYPE definition with the following syntax:
<!DOCTYPE root-element SYSTEM "filename">
Example:-
DTD(Cont’d)<?xml version="1.0"?>
<!DOCTYPE note SYSTEM "note.dtd"><note> <to>Hari</to> <from>Anupam</from> <heading>Reminder</heading> <body>Don't forget me this weekend!</body></note>
And this is the file "note.dtd" which contains the DTD:<!ELEMENT note (to,from,heading,body)>
<!ELEMENT to (#PCDATA)><!ELEMENT from (#PCDATA)><!ELEMENT heading (#PCDATA)><!ELEMENT body (#PCDATA)>
DTD (cont’d)Occurrence Indicator:Indicator Occurrence
(no indicator) Required One and only one
? Optional None or one
* Optional, repeatable
None, one, or more
+ Required, repeatable
One or more
DTD Declaring contentDeclaring either/or Content
<!ELEMENT note (to,from,header,(message|body))>
i.e. either message or bodyDeclaring Mixed Content
<!ELEMENT note (#PCDATA|to|from|header|message)*>
note element can contain zero or more occurrences of parsed character data, "to", "from", "header", or "message" elements
DTD Attributes<!ATTLIST element-name attribute-name
attribute-type default-value> In a DTD, attributes are declared with an
ATTLIST declaration.Example:
<!ATTLIST payment type CDATA "check">
Then the XML example can be as follows: <payment type="check" />
DTD Attributes cont..
XML Summary XML can be used to exchange, share, and store
data. XML documents form a tree structure that starts at
"the root" and branches to "the leaves". XML has very simple syntax rules. XML with
correct syntax is "Well Formed". Valid XML also validates against a DTD.
All modern browsers have a built-in XML parser that can read and manipulate XML.
Text inside a #PCDATA section is parsed by the parser.
Text inside a CDATA section is ignored by the parser.