Introduction to XML (Extensible Markup Language)
- was design to describe data and focus what data is.
- with XML, we can invent our own tag, an example like <to> and <from> which are not defined in any XML standard.
- XML is not a complement to HTML as it is a software- and hardware-independent tool for carrying information.
- difference between XML and HTML:
XML | HTML |
---|---|
Designed to transport data, with focus on what data is. | Design to display data with focus on how data looks looks. |
About displaying information. | About carrying information. |
How can XML be used?
- used widely in aspects of web development often to simplify data storage and sharing.
- XML separates data from HTML.
- data can be stored in separate XML files.
- with a few lines of JavaScript, you can read an external XML files and update the data content without interrupt the HTML data.
- since data is stored in text format, thus easier to expand or upgrade to new operating system, new applications, or new browsers, without losing data.
- Foundation for several next-gen Web technologies sucg as XHTML, WSDL, WAP. WML, RSS, RDF, OWL and SMIL.
- XML documents form a tree structure that start at "the root"and branched to "the leaves"
- An example of XML data:
The syntax Rules:
- All element must have a closing tag.
- XML tag are case sensitive, thus tag <Letter> is different with tag <letter>.
- Opening and closing tags must be written with the same case.
- XML must be properly nested within each other. If you compare the XML with HTML, XML are properly nested within each other.
XML | HTML |
---|---|
<b><i>This text is bold and italic</i></b> -properly nested |
<b><i>This text is bold and italic</b></i> -not properly nested. |
- must contain one element called parent. This element is called root element.
- just like HTML, XML also can have attributes in name/value pair just like in HTML, and must always be quoted.
The predefined entity references in XML:
Command | Explanation |
---|---|
<!-- This is a comment --> | comment in XML which is similar to HTML command. |
HTML:Hello my name is Tove
Output: Hello my name is Tove
|
XML white-space in a document is not truncated. However, in HTML, multiple white-space truncates the character to one single white-space. |
- new line is stored depend on the type of operating system used:
Type of operating system applications |
How XML store a new line |
---|---|
Windows applications | stored as a pair of characters:
|
Unix applications | stored as a line feed character (LF) |
Macintosh applications | use only a carriage return (CR) character to store a new line. |
XML Element
- An XML element is everything from (including) the element's start tag to (include) the element's end tag.
- can contain other elements, simple text or a mixture of both.
- can also have attributes.
Example of the XML element. |
- from the example above, only book have attribute (catogery="CHILDREN")
XML Naming Rules:
- can contain letters, numbers, and other characters.
- cannot start with number or punctuation character.
- cannot start with xml.
XML extensible:
- XML attributes must always be quoted either single or double quote, both can be used.
- an example:
<person sex="female"> or <person sex='female'>
- if the attribute value itself contain double quotes you can use single quotes, an example:
<gangster name='George "Shotgun" Ziegler'> or <ganster name="George "Shotgun" Ziegler">
XML validation
- XML with correct syntax is "Well Formed" XML
- document must have root element ,
- element must have closing tag,
- tag must case sensitive,
- element must properly nested,
- Attribute must quoted.
- XML validated against a DTD is a "Valid" XML
That's all about XML, for more detail, please do visit http://www.w3schools.com/xml/
No comments:
Post a Comment