this section is talking about frontend view of web
We can format a resource in many ways. For example, We can use HTML to represent a website. However, HTML is too heavy to transfer simple data ( e.g. user name ). We must find other ways to do so. A solution is using XML
and JSON
HTML ( HyperText Markup Language ) is used to create web pages. All websites you see from browser is rendered in HTML.
The following example can show up a page with title This is a title
and content Hello world!
if you save it as .html
file and open it with browser
<html>
<head>
<title>This is a title</title>
</head>
<body>
<p>Hello world!</p>
</body>
</html>
HTML can be rendered with css
and javascript
as a pretty website and this is its only purpose
XML ( Extensible Markup Language ) can represent a nested structure. HTML is formatted in XML!
<?xml version="1.0" encoding="UTF-8"?>
<book>
<chapter id="1">
<name>first</name>
</chapter>
<chapter id="2">
<name>second</name>
</chapter>
</book>
-
Declaration : declare some information about itself
<?xml version="1.0" encoding="UTF-8"?>
-
Tag : begins with < and ends with >
- start-tags :
<section>
- end-tags :
</section>
- empty-element tags :
<section />
- start-tags :
-
Element : a component which either
- begins with a start-tag and ends with a matching end-tag
<Greeting> </Greeting>
- consists only of an empty-element tag
<line-break />
data between start and end tag is its content which may contain
text
orelement
<Greeting> Hello, world <line-break /> </Greeting>
<book> <chapter> <name>first</name> </chapter> </book>
-
Attribute : a name / value pair that exists within a
start-tag
orempty-element
tag<img src="madonna.jpg" alt='Foligno Madonna, by Raphael' />
XML is used to carry data
JSON( JavaScript Object Notation ) can represent a nested structure and easy to read
{
"book": {
"chapter": [
{
"id": "1",
"name": "first"
},
{
"id": "2",
"name": "second"
}
]
}
}
-
Number : a signed decimal number
15
-
String : a sequence of Unicode characters, delimited with double-quotation (
""
)"key"
-
Boolean : either of the values
true
orfalse
true
-
Array : an ordered list, each of which may be of any type. Arrays use square bracket (
[]
) notation with elements being comma-separated (,
)[ 1, 2, 3 ]
[ "a", "b" ]
-
Object : an unordered collection of key / value pairs where the keys are strings, delimited with curly brackets (
{}
) and use commas (,
) to separate each pair{ "id" : 1, "name" : "JasonChiu" }
JSON is also used to carry data but more light-weighted
compare between XML
and JSON
- Pro
- simple syntax
- easy to use in javascript
- Con
- less data types are supported
- Pro
- possible to create dialects
- built in support for namespaces
- Con
- wordy