XML As Tree Structure
XML As Tree Structure
XML As Tree Structure
Page 1
Example of an XML Document
<?xml version=“1.0”/>
<address>
<name>Alice Lee</name>
<email>[email protected]</email>
<phone>212-346-1234</phone>
<birthday>1985-03-22</birthday>
</address>
XML Tree Structure
<root>
<child>
<subchild>.....</subchild>
</child>
</root>
Page 3
Contoh :
Prolog :
• <?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<bookstore>
<book category="cooking">
<title lang="en">Everyday Italian</title> root element
<author>Giada De Laurentiis</author>
<year>2005</year> <bookstore>
<price>30.00</price>
</book>
<book category="children"> <book> element:
<title lang="en">Harry Potter</title> <book category="cooking">
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price> 4 child elements: <title>, <author>, <year>, <price>.
</book> <title lang="en">Everyday
<book category="web"> Italian</title>
<title lang="en">Learning XML</title> <author>Giada De Laurentiis</author>
<author>Erik T. Ray</author> <year>2005</year>
<year>2003</year> <price>30.00</price>
<price>39.95</price>
</book> ends the book element:
</bookstore>
</book>
Page 4
XML Syntax Rules
• XML Documents Must Have a Root Element • Entity References
• < <
• The XML Prolog • > >
• & &
• All XML Elements Must Have a Closing Tag • ' '
• XML Tags are Case Sensitive • " “
Page 5
Well Formed XML Documents
Page 6
Valid XML Documents
• A "well formed" XML document is not the same as a "valid" XML
document.
• A "valid" XML document must be well formed. In addition, it must conform to a
document type definition.
• There are two different document type definitions that can be used
with XML:
• DTD - The original Document Type Definition
• XML Schema - An XML-based alternative to DTD
• A document type definition defines the rules and the legal elements
and attributes for an XML document.
Page 7
VS code – Extensions for XML
Page 8
Ctrl + Shift + P
Page 9
Cobakan file xml berikut, capture pesan error/problem :
Check1.xml
<?xml version="1.0" encoding="UTF-8"?>
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
Check2.xml Check3.xml
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</pheading>
<body>Don't forget me this weekend!</body>
</note>
Page 10
Cobakan file xml dengan validasi xtd berikut :
Note.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE note SYSTEM "Note.dtd">
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
Note.dtd
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE note SYSTEM "Note.dtd">
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
Page 11
Tugas Praktikum
• Menulis Langkah instalasi extension xml di vs code (extension apa saja)
• File : checkx.xml di atas dan hasil capture pesan errornya dalam word
• Hasil percobaan xml dengan file validasi dtd nya. (file dan capture)
https://github.com/redhat-developer/vscode-xml/blob/master/docs/Validation.md#validation-with-
xsd-grammar
Page 12