xml overview
DESCRIPTION
โดย อ.ประพจน์ สุขมานนท์TRANSCRIPT
![Page 1: Xml overview](https://reader034.vdocuments.us/reader034/viewer/2022051513/54641905b4af9f533f8b48a6/html5/thumbnails/1.jpg)
eXtensible Markup Language
![Page 2: Xml overview](https://reader034.vdocuments.us/reader034/viewer/2022051513/54641905b4af9f533f8b48a6/html5/thumbnails/2.jpg)
Markup Language
SGML
WML
GML
..ML
![Page 3: Xml overview](https://reader034.vdocuments.us/reader034/viewer/2022051513/54641905b4af9f533f8b48a6/html5/thumbnails/3.jpg)
Markup Language
� A Markup Language is a computer language that specifies the structure and content of a document by breaking the document down into the series of elements
![Page 4: Xml overview](https://reader034.vdocuments.us/reader034/viewer/2022051513/54641905b4af9f533f8b48a6/html5/thumbnails/4.jpg)
XML
� XML stands for eXtensible Markup Language
� XML is a markup language much like HTML
� It’s a new markup language,developed by the W3C(www.w3.org),mainly to overcome limitations in HTML
� XML was designed to describe data
� XML tags are not predefined in XML.You must define your own tags
![Page 5: Xml overview](https://reader034.vdocuments.us/reader034/viewer/2022051513/54641905b4af9f533f8b48a6/html5/thumbnails/5.jpg)
XML & HTML
� HTML and XML were designed with different goals
� HTML was designed to display data and to focus on how data looks
� XML was designed to describe data and to focus on what data is
� HTML is about displaying information, XML is about describing information
![Page 6: Xml overview](https://reader034.vdocuments.us/reader034/viewer/2022051513/54641905b4af9f533f8b48a6/html5/thumbnails/6.jpg)
XML & HTML
� HTML tag : pre-defined tag<b>John</b>
� XML tag : user-defined tag<Name>John</Name>
![Page 7: Xml overview](https://reader034.vdocuments.us/reader034/viewer/2022051513/54641905b4af9f533f8b48a6/html5/thumbnails/7.jpg)
HTML
<b>025447891</b>
Markup Language
XML
<myphonenumber>025447891</myphonenumber>
Markup Language Example
![Page 8: Xml overview](https://reader034.vdocuments.us/reader034/viewer/2022051513/54641905b4af9f533f8b48a6/html5/thumbnails/8.jpg)
XML Example
<?xml version=“1.0”?><employee><id>001</id><name>Prapoj Sukmanont</name><city>Bangkok</city> <email>[email protected]</email>
</employee>
XML
xml01.xml
![Page 9: Xml overview](https://reader034.vdocuments.us/reader034/viewer/2022051513/54641905b4af9f533f8b48a6/html5/thumbnails/9.jpg)
Element Structure
<tag> Content </tag>
Open Tag(start-tag) Close Tag(end-tag)
Element Name
![Page 10: Xml overview](https://reader034.vdocuments.us/reader034/viewer/2022051513/54641905b4af9f533f8b48a6/html5/thumbnails/10.jpg)
XML Structure
<?xml version=“ 1.0” ?><root>
<child><sub_child></sub_child>
</child><child>
<sub_child></sub_child>
</child></root>
root
child child
sub_child sub_child
![Page 11: Xml overview](https://reader034.vdocuments.us/reader034/viewer/2022051513/54641905b4af9f533f8b48a6/html5/thumbnails/11.jpg)
XML File Structure
Document Elements
Prolog
File name : *.xml
![Page 12: Xml overview](https://reader034.vdocuments.us/reader034/viewer/2022051513/54641905b4af9f533f8b48a6/html5/thumbnails/12.jpg)
Prolog
� XML Declaration� <?xml version=“1.0”?>
� Document Type Declaration� <!DOCTYPE PurchaseOrder SYSTEM “po.dtd”>
� Processing Instruction(PI)� <?xml-stylesheet type=“ text/css” href=“ test.css”?>
![Page 13: Xml overview](https://reader034.vdocuments.us/reader034/viewer/2022051513/54641905b4af9f533f8b48a6/html5/thumbnails/13.jpg)
Document Elements
<employee><id>001</id><name>Prasit Lee</name><city>Bangkok</city> <email>[email protected]</email>
</employee>
![Page 14: Xml overview](https://reader034.vdocuments.us/reader034/viewer/2022051513/54641905b4af9f533f8b48a6/html5/thumbnails/14.jpg)
XML File Structure : Prolog
Document Elements
File name : *.xml
1. XML Declaration
2. Document Type Declaration (DTD)
3. Processing Instruction (PI)
Prolog
![Page 15: Xml overview](https://reader034.vdocuments.us/reader034/viewer/2022051513/54641905b4af9f533f8b48a6/html5/thumbnails/15.jpg)
XML Example
<?xml version=“1.0” ?><employee>
<id>001</id><name>Prasit Lee</name><city>Bangkok</city> <email>[email protected]</email>
</employee>
xml01.xml
![Page 16: Xml overview](https://reader034.vdocuments.us/reader034/viewer/2022051513/54641905b4af9f533f8b48a6/html5/thumbnails/16.jpg)
Thai Language XML Example
<?xml version=“1.0” encoding=“ windows-874” ?><employee>
<id>001</id><name>ประสิทธิ� ลี</name><city>กรุงเทพ</city>
<email>[email protected]</email></employee>
xml01th.xml
![Page 17: Xml overview](https://reader034.vdocuments.us/reader034/viewer/2022051513/54641905b4af9f533f8b48a6/html5/thumbnails/17.jpg)
XML Benefits
Self-describe Data
Data Exchange
Messaging Format for Application
XML BenefitsXML Benefits
So on…(RSS, ebXML, XML Applications…)
CML, MathML, MusicML, VoiceML …
![Page 18: Xml overview](https://reader034.vdocuments.us/reader034/viewer/2022051513/54641905b4af9f533f8b48a6/html5/thumbnails/18.jpg)
Text File & XML File
Text File
1,John,Bangkok2,David,New York3,Peter,London
XML File
<?xml version=“1.0” ?><employee><id>1</id><name>John</name><city>Bangkok</city> <id>2</id><name>David</name><city>New York</city> <id>3</id><name>Peter</name><city>London</city>
</employee>
employee.txt employee.xml
![Page 19: Xml overview](https://reader034.vdocuments.us/reader034/viewer/2022051513/54641905b4af9f533f8b48a6/html5/thumbnails/19.jpg)
Data Exchange ExampleDB Server 1
XML File
<?xml version=“1.0” ?><employee><id>1</id><name>John</name><city>Bangkok</city> <id>2</id><name>David</name><city>New York</city> <id>3</id><name>Peter</name><city>London</city>
</employee>
employee.xml
Database
DB Server 2
Database
XML Parser XML Parser
![Page 20: Xml overview](https://reader034.vdocuments.us/reader034/viewer/2022051513/54641905b4af9f533f8b48a6/html5/thumbnails/20.jpg)
XML Processor
� After the XML document is created, it needs to be evaluated by an application known as an XML processor or XML parser
� Part of the function of the parser is to interpret the document’s code and verify that it satisfies all of the XML specifications for document structure and syntax
� Microsoft developed an XML parser called MSXML (msxml.exe) for its Internet Explorer browser
![Page 21: Xml overview](https://reader034.vdocuments.us/reader034/viewer/2022051513/54641905b4af9f533f8b48a6/html5/thumbnails/21.jpg)
Well-Formed XML
“A Well-Formed XML document contains no syntax
errors and satisfies the specifications for XML codes
as laid out by W3C”
![Page 22: Xml overview](https://reader034.vdocuments.us/reader034/viewer/2022051513/54641905b4af9f533f8b48a6/html5/thumbnails/22.jpg)
1. Root Element
<?xml version=“1.0” ?><employee>
<id>001</id><name>Prapoj Sukmanont</name><city>Bangkok</city><email>[email protected]</email>
</employee>
Root Element
![Page 23: Xml overview](https://reader034.vdocuments.us/reader034/viewer/2022051513/54641905b4af9f533f8b48a6/html5/thumbnails/23.jpg)
2. Element Naming
� XML elements must follow these naming rules
� Names can contain letters,numbers, and other characters.Names must not start with a number or other punctuation characters
� Names must not start with the letter xml(or XML or Xml ...)
� Names cannot contain space,(*,? And +)
� Avoid “ -” and “ .” in names
� The “ :” should not be used in element names
![Page 24: Xml overview](https://reader034.vdocuments.us/reader034/viewer/2022051513/54641905b4af9f533f8b48a6/html5/thumbnails/24.jpg)
Element Naming : Example
<Company><_Company><My_company><First-name><Last.name>
<-Company><9Company><.My_company><Name*><Name?><Name+><xmlbook><first name>
OKNot OK
![Page 25: Xml overview](https://reader034.vdocuments.us/reader034/viewer/2022051513/54641905b4af9f533f8b48a6/html5/thumbnails/25.jpg)
3. Closed Tag
<?xml version=“1.0” ?><employee><id>001</id><name>Prapoj Sukmanont</name><city>Bangkok</city> <email>[email protected]</email></employee>
![Page 26: Xml overview](https://reader034.vdocuments.us/reader034/viewer/2022051513/54641905b4af9f533f8b48a6/html5/thumbnails/26.jpg)
4. Proper Nesting Tag
<ID><name>
</ID></name>
<ID><name>
</name></ID>
![Page 27: Xml overview](https://reader034.vdocuments.us/reader034/viewer/2022051513/54641905b4af9f533f8b48a6/html5/thumbnails/27.jpg)
5. Case-sensitive
<ID><name>
</Name></ID>
<ID><name>
</name></ID>
![Page 28: Xml overview](https://reader034.vdocuments.us/reader034/viewer/2022051513/54641905b4af9f533f8b48a6/html5/thumbnails/28.jpg)
6. Attribute Value
<employee id=001><name>
</name></employee>
<employee id=“001”><name>
</name></employee>
<employee id=‘001’><name>
</name></employee>
![Page 29: Xml overview](https://reader034.vdocuments.us/reader034/viewer/2022051513/54641905b4af9f533f8b48a6/html5/thumbnails/29.jpg)
Element Attribute
� An attribute describes a feature or characteristic of an element .Attributes
are often used to provide additional information about an element .The
syntax for adding an attribute to an element is
� Attribute name constraints:
� The name must begin with a letter or underscore (_)
� Space are not allowed in attribute names
� Attribute names should not begin with the text string “xml”
<element_name attribute_name=“Attribute value”> … </element_name>
![Page 30: Xml overview](https://reader034.vdocuments.us/reader034/viewer/2022051513/54641905b4af9f533f8b48a6/html5/thumbnails/30.jpg)
Well-Formed XML Example
<?xml version=“1.0” ?><employee><id>001</id><name prefix=“Mr”>Prapoj Sukmanont</name><city>Bangkok</city> <email>[email protected]</email>
</employee>
Well-FormedXML
xml02.xml
![Page 31: Xml overview](https://reader034.vdocuments.us/reader034/viewer/2022051513/54641905b4af9f533f8b48a6/html5/thumbnails/31.jpg)
� Normal element
� <Name>Prasit Lee </Name>
� Empty element
� <telephone></telephone>
� <telephone/>
XML Element Types
![Page 32: Xml overview](https://reader034.vdocuments.us/reader034/viewer/2022051513/54641905b4af9f533f8b48a6/html5/thumbnails/32.jpg)
Element Content
![Page 33: Xml overview](https://reader034.vdocuments.us/reader034/viewer/2022051513/54641905b4af9f533f8b48a6/html5/thumbnails/33.jpg)
� Nested element
� Character data
� Reference Entity
� CDATA
� Comment
Element Content
<Start-tag> Content </End-tag>
![Page 34: Xml overview](https://reader034.vdocuments.us/reader034/viewer/2022051513/54641905b4af9f533f8b48a6/html5/thumbnails/34.jpg)
1. Nested Element
…<BOOK>
<TITLE> XML Book </TITLE><AUTHOR>Prasit Lee </AUTHOR>
</BOOK>
![Page 35: Xml overview](https://reader034.vdocuments.us/reader034/viewer/2022051513/54641905b4af9f533f8b48a6/html5/thumbnails/35.jpg)
2. Character Data
…<TITLE> XML Book </TITLE><AUTHOR>Prasit Lee </AUTHOR>…
![Page 36: Xml overview](https://reader034.vdocuments.us/reader034/viewer/2022051513/54641905b4af9f533f8b48a6/html5/thumbnails/36.jpg)
3. Entity Reference
& &< <> >“ "‘ '
![Page 37: Xml overview](https://reader034.vdocuments.us/reader034/viewer/2022051513/54641905b4af9f533f8b48a6/html5/thumbnails/37.jpg)
XML Example
<?xml version=“1.0” ?><Example>
<Statement>if x < y </Statement></Example>
xmlerror1.xml
Not XML Well-formed
![Page 38: Xml overview](https://reader034.vdocuments.us/reader034/viewer/2022051513/54641905b4af9f533f8b48a6/html5/thumbnails/38.jpg)
XML Example
<?xml version=“1.0” ?><Example>
<Statement>if x < y </Statement></Example>
xml03.xml
![Page 39: Xml overview](https://reader034.vdocuments.us/reader034/viewer/2022051513/54641905b4af9f533f8b48a6/html5/thumbnails/39.jpg)
4. CDATA Section
<?xml version=“1.0”?><Example>
<Statement><![CDATA[
if x > y and a < b]]>
</Statement></Example>
xml04.xml
![Page 40: Xml overview](https://reader034.vdocuments.us/reader034/viewer/2022051513/54641905b4af9f533f8b48a6/html5/thumbnails/40.jpg)
CDATA
� Sometimes, an XML document needs to store large blocks of text containing the < and > symbols. In that case, it would be cumbersome to replace all of the < and > symbols with < and > character reference, the code itself will be difficult to read
� Instead of using character references, you can place large blocks of text into a CDATA section
� A CDATA section is a large block text that the XML processor interprets only a text
<![CDATA[Text block
]]>
![Page 41: Xml overview](https://reader034.vdocuments.us/reader034/viewer/2022051513/54641905b4af9f533f8b48a6/html5/thumbnails/41.jpg)
5. Comment
…<BOOK>
<!-- This is comment create by “Prasit” 03.02.2012--><TITLE> XML Book </TITLE><AUTHOR>Prasit Lee </AUTHOR>
</BOOK>