The Extensible Markup Language (XML)
The Extensible Markup Language (XML)
Language (XML)
Outline
Part 1: The basics of creating an XML
document
Part 2: Developing constraints for a well
formed XML document
Part 3: XML and supplementary
technologies
XML Simplifies Things
Elements: <hello>
INCORRECT:
<note date=12/11/2007></note>
Correct:
<note date="12/11/2007"></note>
XML References
References usually allow you to add or include additional
text or markup in an XML document. References always
begin with the symbol "&" ,which is a reserved character and
end with the symbol ";".
XML has two types of references:
Entity References: An entity reference contains a name
between the start and the end delimiters. For example &
where amp is name. The name refers to a predefined string
of text and/or markup.
Character References: These contain references, such as
A, contains a hash mark (“#”) followed by a number. The
number always refers to the Unicode code of a character. In
this case, 65 refers to alphabet "A".
Entity References
<message>salary < 1000</message>
To avoid this error, replace the "<" character with an entity reference:
<message>salary < 1000</message>
There are 5 pre-defined entity references in XML:
< < less than
> > greater than
& & ampersand
' ' apostrophe
" " quotation mark
Only < and & are strictly illegal in XML, but it is a good habit to replace >
with > as well.
XML Files are Trees
address
<note>
<date>2008-01-10</date>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
application will still be able to find the <to>,
<from>, and <body> elements in the XML
document and produce the same output.
Xml can be extended without breaking
applications.
XML Attributes
Attribute values must always be quoted.
Either single or double quotes
<gangster name="George
"Shotgun" Ziegler">
XML Elements vs. Attributes
<person gender="female">
<firstname>Anna</firstname>
<lastname>Smith</lastname>
</person>
Can be written as:
<person>
<gender>female</gender>
<firstname>Anna</firstname>
<lastname>Smith</lastname>
</person>
There are no rules about when to use
attributes or when to use elements in XML.
Avoid XML Attributes?
Some things to consider when using attributes
are:
attributes cannot contain multiple values
(elements can)
attributes cannot contain tree structures
(elements can)
attributes are not easily expandable (for
future changes)
Don't end up like this: <note day="10"
month="01" year="2008"
to="Tove" from="Jani" heading="Reminder"
body="Don't forget me this weekend!">
</note>
Well-Formed Documents
An XML document is said to be well-formed if it follows all the
rules.
An XML parser is used to check that all the rules have been
obeyed.
Recent browsers such as Internet Explorer 5 and Netscape 7
come with XML parsers.
Parsers are also available for free download over the Internet.
One is Xerces, from the Apache open-source project.
Java 1.4 also supports an open-source parser.
A "Valid" XML document is a "Well Formed" XML document,
which also conforms to the rules of a Document Type
Definition(DTD) or XML schema
Applications of XML
few example
– Cell Phones : Android App
– File Converters
– Voice XML
– Web Publishing
– Web Searching and automating Web Task
– Meta data applications
- Web services
Benefits of XML
• XML format is not a computer language. It is highly human
readable. It is not difficult to code compared to HTML(XML tags
are highly user defined).
• XML is highly compatible with Java and is hundred percent
portable.
• Any application regardless of the platform or architecture can us
the XML data
• XML is highly extendable - can create our own tags or can use t
tags created by others.
• Complex data searches can be easily performed in XML
documents.
• XML data can be made to display on different types of devices.
Drawbacks of XML