XML
- Extensible Markup Language (XML) is a data storage toolkit, a configurable vehicle for any kind of information, an evolving and open standard embraced by everyone from bankers to webmasters. On one level, XML is a protocol for containing and managing information.
- XML is not itself a markup language: it's a set of rules for building markup languages.So what exactly is a markup language? Markup is information added to a document that enhances its meaning in certain ways, in that it identifies the parts and how they relate to each other.
- XML was designed to transport and store data.
What is XML?
- XML stands for EXtensible Markup Language
- 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
Example:
<message>
<exclamation>Hello, world!</exclamation>
<paragraph>XML is <emphasis>fun</emphasis> and
<emphasis>easy</emphasis> to use.
<graphic fileref="smiley_face.pict"/></paragraph>
</message>
This snippet includes the following markup symbols, or tags:
• The tags <message> and </message> mark the start and end points of the whole XML fragment.
• The tags <exclamation> and </exclamation> surround the text Hello, world!.
• The tags <paragraph> and </paragraph> surround a larger region of text and tags.
• Some <emphasis> and </emphasis> tags label individual words.
• A <graphic fileref="smiley_face.pict"/> tag marks a place in the text to insert a picture.
- In XML, a document is even more general: it's the basic unit of XML information, composed of elements and other markup in an orderly package.
- One of the most promising applications of XML is as a format for application-to-application data exchange.- There are two ways for creating a language based on XML. The first is called freeform XML. In this mode,there are some minimal rules about how to form and use tags, but any tag names can be used and they can appear in any order. This is sort of like making up your own words but observing rules of punctuation. When a document satisfies the minimal rules of XML, it is said to be well-formed, and qualifies as good XML.
- XML provides a way to describe your language in no uncertain terms. This is called document modeling, because it involves creating a specification that lays out the rules for how a document can look. In effect, it is a model against which you can compare a particular document (referred to as a document instance) to see if it truly represents your language, so you can test your document to make sure it matches your language specification. We call this test validation. If your document is found to be valid, you know it's free from mistakes such as incorrect tag spelling, improper ordering, and missing data.
- The most common way to model documents is with a document type definition (DTD). This is a set of rules or declarations that specify which tags can be used and what they can contain. At the top of your document is a reference to the DTD, declaring your desire to have the document validated.
- The most fundamental XML processor reads XML documents and converts them into an internal representation for other programs or subroutines to use. This is called a parser, and it is an important component of every XML processing program. The parser turns a stream of characters from files into meaningful chunks of information called tokens. The tokens are either interpreted as events to drive a program, or are built into a temporary structure in memory (a tree representation) that a program can act on.
- There are three steps for parsing an XML document. The parser reads in the XML from files on a computer (1). It translates the stream of characters into bite-sized tokens (2). Optionally, the tokens can be used to assemble in memory an abstract representation of the document, an object tree (3).
• 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 concentrate on using HTML for layout and display, 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.
• XML Simplifies Data Sharing
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.
• 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.
• XML Simplifies Platform Changes
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.
• XML Makes Your Data More Available
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.
XML Syntax Rules
- All XML Elements Must Have a Closing Tag
- XML Tags are Case Sensitive
- XML Elements Must be Properly Nested
- XML Documents Must Have a Root Element
- XML Attribute Values Must be Quoted
- White-space is Preserved in XML
- Entity References
There are 5 predefined entity references in XML:
< < less than
> > greater than
& & ampersand
' ' Apostrophe
" " quotation mark
-What is an XML Element?
An XML element is everything from (including) the element's start tag to (including) the element's end tag.
An element can contain:
• other elements
• text
• attributes
• or a mix of all of the above...
<bookstore>
<book category="CHILDREN">
<title>Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>
<book category="WEB">
<title>Learning XML</title>
<author>Erik T. Ray</author>
<year>2003</year>
<price>39.95</price>
</book>
</bookstore>
In the example above, <bookstore> and <book> have element contents, because they contain other elements. <book> also has an attribute (category="CHILDREN"). <title>, <author>, <year>, and <price> have text content because they contain text.
-XML elements must follow these naming rules:
• Names can contain letters, numbers, and other characters
• Names cannot start with a number or punctuation character
• Names cannot start with the letters xml (or XML, or Xml, etc)
• Names cannot contain spaces
History of XML
SGML was designed to be a flexible and all-encompassing coding scheme. Like XML, it is basically a toolkit for developing specialized markup languages. But SGML is much bigger than XML, with a looser syntax and lots of soteric parameters. It's so flexible that software built to process it is complex and expensive, and its usefulness is limited to large organizations that can afford both the software and the cost of maintaining complicated SGML.
The public revolution in generic coding came about in the early 1990s, when Hypertext Markup Language (HTML) was developed by Tim Berners-Lee and Anders Berglund. Berners-Lee and Berglund created an SGML document type for hypertext documents that was compact and efficient. It was easy to write software for this markup language, and even easier to encode documents. HTML escaped from the lab and went on to take over the world. However, HTML was in some ways a step backward. To achieve the simplicity necessary to be truly useful, some principles of generic coding had to be sacrificed. For example, one document type was used for all purposes,forcing people to overload tags rather than define specific-purpose tags. Second, many of the tags are purely presentational. The simplistic structure made it hard to tell where one section began and another ended. Many HTML-encoded documents today are so reliant on pure formatting that they can't be easily repurposed. To return to the ideals of generic coding, some people tried to adapt SGML for the Web—or rather, to adapt the Web to SGML. This proved too difficult. SGML was too big to squeeze into a little web browser. A smaller language that still retained the generality of SGML was required, and thus was born the Extensible Markup Language (XML).
XML Attributes
In HTML, attributes provide additional information about elements:
<img src="computer.gif">
<a href="demo.asp">
-Attributes often provide information that is not a part of the data. In the example below, the file type is irrelevant to the data, but can be important to the software that wants to manipulate the element:
<file type="gif">computer.gif</file>
-Attribute values must always be quoted. Either single or double quotes can be used. For a person's sex, the person element can be written like this:
<person sex="female"> or like this <person sex='female'>
-Some of the problems with 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)
-Attributes are difficult to read and maintain. Use elements for data. Use attributes for information that is not relevant to the data.
XML Validation
XML with correct syntax is "Well Formed" XML. XML validated against a DTD is "Valid" XML.
-Well Formed XML Documents
A "Well Formed" XML document has correct XML 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>
-Valid XML Documents
A "Valid" XML document is a "Well Formed" XML document, which also conforms to the rules of a Document Type Definition (DTD). The purpose of a DTD is to define the structure of an XML document. It defines the structure with a list of legal elements. The below will be the DTD for the example shown above:
<!DOCTYPE note
[
<!ELEMENT note (to,from,heading,body)>
<!ELEMENT to (#PCDATA)>
<!ELEMENT from (#PCDATA)>
<!ELEMENT heading (#PCDATA)>
<!ELEMENT body (#PCDATA)>
]>
-PCDATA is Parsed Character Data, which is the text that will be parsed by the parser. The text will be examined by the parser for entities and markups. Tags inside the text will be treated as markups and entities will be expanded. Parsed Character Data should not contain any & , < or > symbols , these should be represented by the & , < , > entities.
-CDATA is text that will not be parsed by a parser.
No comments:
Post a Comment