Extensible
Preview XML di atas :
Contoh dengan XML outline :
dibagi jadi 2 file yaitu file xml dan file dtd
a. dalam file dtd
<!ELEMENT laptop_asus (laptop*)>
<!ELEMENT laptop (edisi, spesifikasi_hw, penampakan)>
<!ELEMENT edisi (#PCDATA)>
<!ELEMENT spesifikasi_hw (prosesor, graphic, storage, battery)>
<!ELEMENT prosesor (#PCDATA)>
<!ELEMENT graphic (#PCDATA)>
<!ELEMENT storage (#PCDATA)>
<!ELEMENT battery (#PCDATA)>
<!ELEMENT penampakan (dimensi, berat)>
<!ELEMENT dimensi (#PCDATA)>
<!ELEMENT berat (#PCDATA)>
<!ATTLIST laptop
tipe CDATA #REQUIRED>
b. dalam file xml
<?xml version="1.0"?>
<!DOCTYPE laptop_asus SYSTEM "laptop_asus.dtd">
<laptop_asus>
<laptop tipe="B23E">
<edisi>Business</edisi>
<spesifikasi_hw>
<prosesor> Intel Core i3, i5, i7 Processor</prosesor>
<graphic>Integrated Intel HP Graphic 3000</graphic>
<storage>2.5" SATA 320GB - 750GB</storage>
<battery>3Cells 4400 mAh 48 Whrs</battery>
</spesifikasi_hw>
<penampakan>
<dimensi>30.5 x 20.6 x 2.8 cm (WxDxH)</dimensi>
<berat>1.55 kg (with battery)</berat>
</penampakan>
</laptop>
<laptop tipe="G51J">
<edisi>Gaming Powerhouse</edisi>
<spesifikasi_hw>
<prosesor> Intel Core i7 Processor</prosesor>
<graphic>NVDIA GeForce GTX 260M with 1GB DDR3 VRAM</graphic>
<storage>2.5" SATA 250GB - 500GB</storage>
<battery>6Cells : 4800mAh - 9Cells : 7200 mAh</battery>
</spesifikasi_hw>
<penampakan>
<dimensi>37.5 x 26.5 x 3.43 ~4.06 cm (WxDxH)</dimensi>
<berat>3.30 kg (with battery)</berat>
</penampakan>
</laptop>
<laptop tipe="U33J">
<edisi>Special Edition --> Bamboo Series</edisi>
<spesifikasi_hw>
<prosesor> Intel Core i3, i5 Processor</prosesor>
<graphic>NVIDIA GeForce 310M with 1GB DDR3 VRAM</graphic>
<storage>2.5" SATA 320GB - 640GB</storage>
<battery>6Cells : 4400mAh - 8Cells : 4400 mAh</battery>
</spesifikasi_hw>
<penampakan>
<dimensi>32.8 x 23.2 x 1.48 ~3.10 cm (WxDxH)</dimensi>
<berat>1.9 kg (with battery)</berat>
</penampakan>
</laptop>
</laptop_asus>
Contoh dengan XML schema :
xml schema dibuat dengan menggunakan fasilitas dari microsoft visual studio.
a. dalam file xml
<?xml version="1.0"?>
<laptop_asus xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="laptop_asus_schema.xsd">
<laptop tipe="B23E">
<edisi>Business</edisi>
<spesifikasi_hw>
<prosesor> Intel Core i3, i5, i7 Processor</prosesor>
<graphic>Integrated Intel HP Graphic 3000</graphic>
<storage>2.5" SATA 320GB - 750GB</storage>
<battery>3Cells 4400 mAh 48 Whrs</battery>
</spesifikasi_hw>
<penampakan>
<dimensi>30.5 x 20.6 x 2.8 cm (WxDxH)</dimensi>
<berat>1.55 kg (with battery)</berat>
</penampakan>
</laptop>
<laptop tipe="G51J">
<edisi>Gaming Powerhouse</edisi>
<spesifikasi_hw>
<prosesor> Intel Core i7 Processor</prosesor>
<graphic>NVDIA GeForce GTX 260M with 1GB DDR3 VRAM</graphic>
<storage>2.5" SATA 250GB - 500GB</storage>
<battery>6Cells : 4800mAh - 9Cells : 7200 mAh</battery>
</spesifikasi_hw>
<penampakan>
<dimensi>37.5 x 26.5 x 3.43 ~4.06 cm (WxDxH)</dimensi>
<berat>3.30 kg (with battery)</berat>
</penampakan>
</laptop>
<laptop tipe="U33J">
<edisi>Special Edition --> Bamboo Series</edisi>
<spesifikasi_hw>
<prosesor> Intel Core i3, i5 Processor</prosesor>
<graphic>NVIDIA GeForce 310M with 1GB DDR3 VRAM</graphic>
<storage>2.5" SATA 320GB - 640GB</storage>
<battery>6Cells : 4400mAh - 8Cells : 4400 mAh</battery>
</spesifikasi_hw>
<penampakan>
<dimensi>32.8 x 23.2 x 1.48 ~3.10 cm (WxDxH)</dimensi>
<berat>1.9 kg (with battery)</berat>
</penampakan>
</laptop>
</laptop_asus>
b. dalam file xsd
<?xml version="1.0" encoding="utf-8"?>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="laptop_asus">
<xs:complexType>
<xs:sequence>
<xs:element maxOccurs="unbounded" name="laptop">
<xs:complexType>
<xs:sequence>
<xs:element name="edisi" type="xs:string" />
<xs:element name="spesifikasi_hw">
<xs:complexType>
<xs:sequence>
<xs:element name="prosesor" type="xs:string" />
<xs:element name="graphic" type="xs:string" />
<xs:element name="storage" type="xs:string" />
<xs:element name="battery" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="penampakan">
<xs:complexType>
<xs:sequence>
<xs:element name="dimensi" type="xs:string" />
<xs:element name="berat" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="tipe" type="xs:string" use="required" />
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Untuk menentukan valid tidaknya sebuah file xml dapat dilakukan dengan 2 cara :
1. dengan membukanya di browser (jika dapat terbaca, dapat dikatakan bahwa xml sudah lumayan standart)
2. untuk lebih tepatnya / lebih valid dapat dites dengan diupload di http://validator.w3.org/.
Markup
Language
(XML)
HTML = display (formated) information on the web browser, sedangkan
XML = create your own tag.
XML digunakan saat membutuhkan portabilitas & standarisasi dari pertukaran dokumen.
Contoh :
Penerbit buku ingin memberi update info produk kepada retailernya. (via)
1. Text file à kirim via e-mail, copas ke db u/ aplikasi e-commerce
Portable, karena dapat dikirim kemana-mana namun tidak standar krn text file belum dapat dipakai untuk multiplatform.
2. Pdf à kirim via email, parser ke db untuk aplikasi e-commerce
Portable kern dpt dikirim ke mana tapi tidak standar karena parser tiap bulan berbeda-beda
3. SQL à kirim via email, restore ke db untuk aplikasi e-commerce
Tidak portable karena tidak dapat digunakan di db lain, namun standar karena format di dalamnya memeiliki standarisasi
4. XML à kirim via email, parsing ke db untuk aplikasi e-commerce
Portable dan standar.
Tag pada XML case sensitive dan tidak boleh dipisah oleh spasi. Untuk memberi / menentukan standar XML :
1. DTD (Document Type Definition)
Ditulis dengan 2 cara :
a. Inline / internal DTD
b. Outline (masih belum)
2. XML Schema
Contoh XML dengan DTD inline
<!DOCTYPE asus[
<!ELEMENT asus (laptop+)>
<!ELEMENT laptop (edisi, tipe, spesifikasi_hw, penampakan)>
<!ELEMENT edisi (#PCDATA)>
<!ELEMENT tipe (#PCDATA)>
<!ELEMENT spesifikasi_hw (prosesor, graphic, storage, battery)>
<!ELEMENT prosesor (#PCDATA)>
<!ELEMENT graphic (#PCDATA)>
<!ELEMENT storage (#PCDATA)>
<!ELEMENT battery (#PCDATA)>
<!ELEMENT penampakan (dimensi, berat)>
<!ELEMENT dimensi (#PCDATA)>
<!ELEMENT berat (#PCDATA)>
]>
<asus>
<laptop>
<edisi>Business</edisi>
<tipe>B23E</tipe>
<spesifikasi_hw>
<prosesor>Intel Core i3 - i7 Processor</prosesor>
<graphic>Integrated Intel HP Graphic 3000</graphic>
<storage>2.5" SATA 320GB - 750GB</storage>
<battery>3Cells 4400 mAh 48 Whrs</battery>
</spesifikasi_hw>
<penampakan>
<dimensi>30.5 x 20.6 x 2.8 cm (WxDxH)</dimensi>
<berat>1.55 kg (with battery)</berat>
</penampakan>
</laptop>
<laptop>
<edisi>Gaming Powerhouse</edisi>
<tipe>G51J</tipe>
<spesifikasi_hw>
<prosesor>Intel Core i7 Processor</prosesor>
<graphic>NVDIA GeForce GTX 260M with 1GB DDR3 VRAM</graphic>
<storage>2.5" SATA 250GB - 500GB</storage>
<battery>6Cells : 4800mAh - 9Cells : 7200 mAh</battery>
</spesifikasi_hw>
<penampakan>
<dimensi>37.5 x 26.5 x 3.43 ~4.06 cm (WxDxH)</dimensi>
<berat>3.30 kg (with battery)</berat>
</penampakan>
</laptop>
<laptop>
<edisi>Special Edition --> Bamboo Series</edisi>
<tipe>U33Jc</tipe>
<spesifikasi_hw>
<prosesor>Intel Core i3 - i5 Processor</prosesor>
<graphic>NVIDIA GeForce 310M with 1GB DDR3 VRAM</graphic>
<storage>2.5" SATA 320GB - 640GB</storage>
<battery>6Cells : 4400mAh - 8Cells : 4400 mAh</battery>
</spesifikasi_hw>
<penampakan>
<dimensi>32.8 x 23.2 x 1.48 ~3.10 cm (WxDxH)</dimensi>
<berat>1.9 kg (with battery)</berat>
</penampakan>
</laptop>
</asus>
Preview XML di atas :
dibagi jadi 2 file yaitu file xml dan file dtd
a. dalam file dtd
<!ELEMENT laptop_asus (laptop*)>
<!ELEMENT laptop (edisi, spesifikasi_hw, penampakan)>
<!ELEMENT edisi (#PCDATA)>
<!ELEMENT spesifikasi_hw (prosesor, graphic, storage, battery)>
<!ELEMENT prosesor (#PCDATA)>
<!ELEMENT graphic (#PCDATA)>
<!ELEMENT storage (#PCDATA)>
<!ELEMENT battery (#PCDATA)>
<!ELEMENT penampakan (dimensi, berat)>
<!ELEMENT dimensi (#PCDATA)>
<!ELEMENT berat (#PCDATA)>
<!ATTLIST laptop
tipe CDATA #REQUIRED>
b. dalam file xml
<?xml version="1.0"?>
<!DOCTYPE laptop_asus SYSTEM "laptop_asus.dtd">
<laptop_asus>
<laptop tipe="B23E">
<edisi>Business</edisi>
<spesifikasi_hw>
<prosesor> Intel Core i3, i5, i7 Processor</prosesor>
<graphic>Integrated Intel HP Graphic 3000</graphic>
<storage>2.5" SATA 320GB - 750GB</storage>
<battery>3Cells 4400 mAh 48 Whrs</battery>
</spesifikasi_hw>
<penampakan>
<dimensi>30.5 x 20.6 x 2.8 cm (WxDxH)</dimensi>
<berat>1.55 kg (with battery)</berat>
</penampakan>
</laptop>
<laptop tipe="G51J">
<edisi>Gaming Powerhouse</edisi>
<spesifikasi_hw>
<prosesor> Intel Core i7 Processor</prosesor>
<graphic>NVDIA GeForce GTX 260M with 1GB DDR3 VRAM</graphic>
<storage>2.5" SATA 250GB - 500GB</storage>
<battery>6Cells : 4800mAh - 9Cells : 7200 mAh</battery>
</spesifikasi_hw>
<penampakan>
<dimensi>37.5 x 26.5 x 3.43 ~4.06 cm (WxDxH)</dimensi>
<berat>3.30 kg (with battery)</berat>
</penampakan>
</laptop>
<laptop tipe="U33J">
<edisi>Special Edition --> Bamboo Series</edisi>
<spesifikasi_hw>
<prosesor> Intel Core i3, i5 Processor</prosesor>
<graphic>NVIDIA GeForce 310M with 1GB DDR3 VRAM</graphic>
<storage>2.5" SATA 320GB - 640GB</storage>
<battery>6Cells : 4400mAh - 8Cells : 4400 mAh</battery>
</spesifikasi_hw>
<penampakan>
<dimensi>32.8 x 23.2 x 1.48 ~3.10 cm (WxDxH)</dimensi>
<berat>1.9 kg (with battery)</berat>
</penampakan>
</laptop>
</laptop_asus>
Contoh dengan XML schema :
xml schema dibuat dengan menggunakan fasilitas dari microsoft visual studio.
a. dalam file xml
<?xml version="1.0"?>
<laptop_asus xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="laptop_asus_schema.xsd">
<laptop tipe="B23E">
<edisi>Business</edisi>
<spesifikasi_hw>
<prosesor> Intel Core i3, i5, i7 Processor</prosesor>
<graphic>Integrated Intel HP Graphic 3000</graphic>
<storage>2.5" SATA 320GB - 750GB</storage>
<battery>3Cells 4400 mAh 48 Whrs</battery>
</spesifikasi_hw>
<penampakan>
<dimensi>30.5 x 20.6 x 2.8 cm (WxDxH)</dimensi>
<berat>1.55 kg (with battery)</berat>
</penampakan>
</laptop>
<laptop tipe="G51J">
<edisi>Gaming Powerhouse</edisi>
<spesifikasi_hw>
<prosesor> Intel Core i7 Processor</prosesor>
<graphic>NVDIA GeForce GTX 260M with 1GB DDR3 VRAM</graphic>
<storage>2.5" SATA 250GB - 500GB</storage>
<battery>6Cells : 4800mAh - 9Cells : 7200 mAh</battery>
</spesifikasi_hw>
<penampakan>
<dimensi>37.5 x 26.5 x 3.43 ~4.06 cm (WxDxH)</dimensi>
<berat>3.30 kg (with battery)</berat>
</penampakan>
</laptop>
<laptop tipe="U33J">
<edisi>Special Edition --> Bamboo Series</edisi>
<spesifikasi_hw>
<prosesor> Intel Core i3, i5 Processor</prosesor>
<graphic>NVIDIA GeForce 310M with 1GB DDR3 VRAM</graphic>
<storage>2.5" SATA 320GB - 640GB</storage>
<battery>6Cells : 4400mAh - 8Cells : 4400 mAh</battery>
</spesifikasi_hw>
<penampakan>
<dimensi>32.8 x 23.2 x 1.48 ~3.10 cm (WxDxH)</dimensi>
<berat>1.9 kg (with battery)</berat>
</penampakan>
</laptop>
</laptop_asus>
b. dalam file xsd
<?xml version="1.0" encoding="utf-8"?>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="laptop_asus">
<xs:complexType>
<xs:sequence>
<xs:element maxOccurs="unbounded" name="laptop">
<xs:complexType>
<xs:sequence>
<xs:element name="edisi" type="xs:string" />
<xs:element name="spesifikasi_hw">
<xs:complexType>
<xs:sequence>
<xs:element name="prosesor" type="xs:string" />
<xs:element name="graphic" type="xs:string" />
<xs:element name="storage" type="xs:string" />
<xs:element name="battery" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="penampakan">
<xs:complexType>
<xs:sequence>
<xs:element name="dimensi" type="xs:string" />
<xs:element name="berat" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="tipe" type="xs:string" use="required" />
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Untuk menentukan valid tidaknya sebuah file xml dapat dilakukan dengan 2 cara :
1. dengan membukanya di browser (jika dapat terbaca, dapat dikatakan bahwa xml sudah lumayan standart)
2. untuk lebih tepatnya / lebih valid dapat dites dengan diupload di http://validator.w3.org/.
