XML
- Extensible Markup Language
- A computer language which uses mark up and is capable of being extended
- Mark up: (Literally) Notations or symbols that are used to correct in making up text and indicate how text should be displayed (<, >, ? etc..)
- Mark up refers to the sequence of characters or other symbols that can be inserted at certain places in text file, to indicate how a file should look when it is printed or displayed
- Extensible: a program or programming language that is designed so that users and developers can expand or add to its capabilities.
Ex:
<name>vishwak</name>
<email>vishwak.kurapati@gmail.com </email>
<number>9405881515</number>
Red- markups
Black- Normal text
Tags and elements:
<name>→start tag
</name>→end tag
/→slash or solidus
<name>vishwak</name>--> Element (element name must start with letter or underscore and can have letters, digits, period, underscore etc .. but not white space)
Element name is name
Element value is vihwak
Rules:
- XML element names are case sensitive
- XML document should have one root element
- Elements should not be overlapped
Structure of XML elements:
<parent>
<child>
<sub-child>…………..</sub-child>
</child>
</parent>
XML declaration or prolog:
<? xml version=”1.0” encoding=”UTF-8” ?>
version=”1.0” – Version of XML
UTF- Universal Character Set Transformation Format
There is no end tag for this, hence it is not an element it is a declaration.
- It is optional. If it is appears in document then it should be on top. Not even white space or comment come before it
- All XML parsers are required to support UTF-8 and UTF-16
- This declaration is case sensitive
Attributes:
It specifies a single property for an element. It consists of name and value separated by equal sign.
<book name=”mine”>
name=”mine”→attribute
name →attribute name(case sensitive)
mine→value(Always within quotation marks , single or double)
- Attribute is only placed after the start tag with white space associated
- Only one value for the same attribute in the same start tag
References:
A reference is used to add additional text or markup in XML document, where an error may occur if the character is typed directly. Such as < , &, >, etc.. can be replaced by &, <, >, etc.
- References start with & and ends with ;
References are of two types:
Entity references: starts with & and ends with ;
Character references: starts with &# and ends with ; ex: a→a, A→A, Z→ z etc.
Comments:
Declaration: <!—comment goes here-->
→Comments are place anywhere expect inside tag and top of the XML
→XML comments cannot be nested
Empty XML elements: Elements with no value
<element></element> or <element/>
XML was not designed to display data like HTML. XML doesn’t have predefined tags.
Uses of XML:
XML can separate data from HTML.
XML is used to exchange data
XML can be used to share data
XML can be used to store data
XML can make your data more useful
XML can be used to create new *ML languages
Elements vs attributes:
Attributes cannot contains 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 Document Type Definition – DTD: Which is used to define legal elements of an xml document.
No comments:
Post a Comment