Anda di halaman 1dari 7

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
The Difference Between XML and HTML
XML is not a replacement for HTML.
XML and HTML were designed with different goals:
XML was designed to transport and store data, with focus on what data is
HTML was designed to display data, with focus on how data looks
HTML is about displaying information, while XML is about carrying information.
All XML Elements Must Have a Closing Tag
In HTML, some elements do not hae to hae a closing tag:
!p"This is a paragraph.
!br"
In XML, it is illegal to omit the closing tag. #ll elements must hae a closing tag:
!p"This is a paragraph.!$p"
!br $"
XML Tags are Case ensitive
XML tags are case sensitie. The tag !Letter" is different from the tag !letter".
%pening and closing tags must be written with the same case:
!Message"This is incorrect!$message"
!message"This is correct!$message"
XML Elements Must !e "ro#erl$ %ested
In HTML, you might see improperly nested elements:
!b"!i"This te&t is bold and italic!$b"!$i"
XML Documents Must Have a &oot Element
XML documents must contain one element that is the #arent of all other elements. This
element is called the root element.
!root"
!child"
!subchild".....!$subchild"
!$child"
!$root"
XML Attri!ute 'alues Must !e (uoted
XML elements can hae attributes in name$alue pairs 'ust like in HTML.
In XML, the attribute alues must always be (uoted.
)tudy the two XML documents below. The first one is incorrect, the second is correct:
!note date*+,$++$,--."
!to"Toe!$to"
!from"/ani!$from"
!$note"
!note date*0+,$++$,--.0"
!to"Toe!$to"
!from"/ani!$from"
!$note"
Entit$ &eferences
)ome characters hae a special meaning in XML.
If you place a character like 0!0 inside an XML element, it will generate an error because the
parser interprets it as the start of a new element.
This will generate an XML error:
!message"if salary ! +--- then!$message"
To aoid this error, replace the 0!0 character with an entit$ reference:
!message"if salary 1lt2 +--- then!$message"
There are 3 predefined entity references in XML:
1lt2 ! less than
1gt2 " greater than
1amp2 1 ampersand
1apos2 4 apostrophe
1(uot2 0 (uotation mark
%ote) %nly the characters 0!0 and 010 are strictly illegal in XML. The greater than character
is legal
Comments in XML
The synta& for writing comments in XML is similar to that of HTML.
!566 This is a comment 66"
What is an XML Element?
#n XML element is eerything from 7including8 the element4s start tag to 7including8 the
element4s end tag.
#n element can contain:
other elements
te&t
attributes
or a mi& of all of the aboe...
!bookstore"
!book category*09HIL:;<=0"
!title"Harry >otter!$title"
!author"/ ?. ;owling!$author"
!year",--3!$year"
!price",@.@@!$price"
!$book"
In the e&ample aboe, !bookstore" and !book" hae element contents, because they contain
other elements. !book" also has an attri!ute 7category*09HIL:;<=08. !title", !author",
!year", and !price" hae te*t content because they contain te&t.
XML Attri!utes
In HTML, attributes proide additional information about elements:
img src!"computer.gif"#
a href!"demo.asp"#
#ttributes often proide information that is not a part of the data. In the e&ample below, the
file type is irreleant to the data, but can be important to the software that wants to
manipulate the element:
file type!"gif"#computer.gif$file#
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'iewing XML +iles
;aw XML files can be iewed in all ma'or browsers.
:on4t e&pect XML files to be displayed as HTML pages.
&'ml (ersion!").*" encoding!"+,-%../0%)"&#
% note#
to#Tove$to#
from#Jani$from#
heading#Reminder$heading#
body#Don't forget me this weekend!$body#
$note#
'iewing an ,nvalid XML +ile
If an erroneous XML file is opened, the browser will report the error.
XML Document -!.ect model
The XML :%M defines a standard way for accessing and manipulating XML documents.
The :%M presents an XML document as a tree6structure.
?nowing the XML :%M is a must for anyone working with XML.
The HTML D-M
The HTML :%M defines a standard way for accessing and manipulating HTML documents.
#ll HTML elements can be accessed through the HTML :%M.
What is A/AX?
#/#X * #synchronous /aa)cript and XML.
#/#X is a techni(ue for creating fast and dynamic web pages.
#/#X is about updating parts of a web page, without reloading the whole page.
#/#X allows web pages to be updated asynchronously by e&changing small amounts of data
with the serer behind the scenes. This means that it is possible to update parts of a web page,
without reloading the whole page.
9lassic web pages, 7which do not use #/#X8 must reload the entire page if the content
should change.
<&amples of applications using #/#X: Aoogle Maps, Amail, Boutube, and Cacebook tabs.
A/AX is Based on ,nternet tandards
#/#X is based on internet standards, and uses a combination of:
XMLHttp;e(uest ob'ect 7to e&change data asynchronously with a serer8
/aa)cript$:%M 7to display$interact with the information8
9)) 7to style the data8
XML 7often used as the format for transferring data8
#/#X applications are browser6 and platform6independent5
The XMLHtt#&e0uest -!.ect
#ll modern browsers support the XMLHttp;e(uest ob'ect 7I<3 and I<D use an
#ctieX%b'ect8.
The XMLHttp;e(uest ob'ect is used to e&change data with a serer behind the scenes. This
means that it is possible to update parts of a web page, without reloading the whole page.
)ynta& for creating an XMLHttp;e(uest ob'ect:
variable*new XMLHttp;e(uest782
end a &e0uest To a erver
To send a re(uest to a serer, we use the open78 and send78 methods of the XMLHttp;e(uest
ob'ect:
'mlhttp.open1"2ET","a3a'4info.t't",true56
'mlhttp.send156
erver &es#onse
To get the response from a serer, use the responseTe&t or responseXML property of the
XMLHttp;e(uest ob'ect.
Property Description
responseTe
't
get the response data as a string
responseXM
L
get the response data as XML data
The res#onseTe*t "ro#ert$
If the response from the serer is not XML, use the responseTe&t property.
The responseTe&t property returns the response as a string, and you can use it accordingly:
E*am#le
document.getElement7y+d1"my8i("5.innerHTML!'mlhttp.responseTe't6

Anda mungkin juga menyukai