SlideShare a Scribd company logo
1 of 12
BAB III Memformat XML
Viewing XML Files




Raw XML files can be viewed in all major browsers.

Don't expect XML files to be displayed as HTML pages.




Viewing XML Files


<?xml version="1.0" encoding="ISO-8859-1"?>
- <note>
   <to>Tove</to>
   <from>Jani</from>
   <heading>Reminder</heading>
   <body>Don't forget me this weekend!</body>
  </note>
Look at this XML file: note.xml
The XML document will be displayed with color-coded root and child elements. A plus (+) or minus sign (-) to the
left of the elements can be clicked to expand or collapse the element structure. To view the raw XML source
(without the + and - signs), select "View Page Source" or "View Source" from the browser menu.
Note: In Netscape, Opera, and Safari, only the element text will be displayed. To view the raw XML, you must right
click the page and select "View Source"




Viewing an Invalid XML File

If an erroneous XML file is opened, the browser will report the error.
Look at this XML file: note_error.xml




Other XML Examples

Viewing some XML documents will help you get the XML feeling.
An XML CD catalog
This is a CD collection, stored as XML data.
An XML plant catalog
This is a plant catalog from a plant shop, stored as XML data.
A Simple Food Menu
This is a breakfast food menu from a restaurant, stored as XML data.




Why Does XML Display Like This?

XML documents do not carry information about how to display the data.
Since XML tags are "invented" by the author of the XML document, browsers do not know if a tag like <table>
describes an HTML table or a dining table.
Without any information about how to display the data, most browsers will just display the XML document as it is.
In the next chapters, we will take a look at different solutions to the display problem, using CSS, XSLT and
JavaScript.




Displaying XML with CSS




With CSS (Cascading Style Sheets) you can add display information to an XML document.




Displaying your XML Files with CSS?

It is possible to use CSS to format an XML document.
Below is an example of how to use a CSS style sheet to format an XML document:
Take a look at this XML file: The CD catalog
Then look at this style sheet: The CSS file
Finally, view: The CD catalog formatted with the CSS file
Below is a fraction of the XML file. The second line links the XML file to the CSS file:

<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/css" href="cd_catalog.css"?>
<CATALOG>
  <CD>
    <TITLE>Empire Burlesque</TITLE>
    <ARTIST>Bob Dylan</ARTIST>
    <COUNTRY>USA</COUNTRY>
    <COMPANY>Columbia</COMPANY>
    <PRICE>10.90</PRICE>
    <YEAR>1985</YEAR>
  </CD>
  <CD>
    <TITLE>Hide your heart</TITLE>
    <ARTIST>Bonnie Tyler</ARTIST>
    <COUNTRY>UK</COUNTRY>
    <COMPANY>CBS Records</COMPANY>
    <PRICE>9.90</PRICE>
    <YEAR>1988</YEAR>
  </CD>
.
.
.
.
</CATALOG>
Formatting XML with CSS is not the most common method.
W3C recommend using XSLT instead. See the next chapter.
Displaying XML with XSLT




With XSLT you can transform an XML document into HTML.




Displaying XML with XSLT

XSLT is the recommended style sheet language of XML.
XSLT (eXtensible Stylesheet Language Transformations) is far more sophisticated than CSS.
One way to use XSLT is to transform XML into HTML before it is displayed by the browser as demonstrated in these
examples:
View the XML file, the XSLT style sheet, and View the result.
Below is a fraction of the XML file. The second line links the XML file to the XSLT file:

<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="simple.xsl"?>
<breakfast_menu>
  <food>
    <name>Belgian Waffles</name>
    <price>$5.95</price>
    <description>
       two of our famous Belgian Waffles
    </description>
    <calories>650</calories>
  </food>
</breakfast_menu>
If you want to learn more about XSLT, find our XSLT tutorial on our homepage.




Transforming XML with XSLT on the Server

In the example above, the XSLT transformation is done by the browser, when the browser reads the XML file.
Different browsers may produce different result when transforming XML with XSLT. To reduce this problem the XSLT
transformation can be done on the server.
View the result.
Note that the result of the output is exactly the same, either the transformation is done by the web server or by the
web browser.
Displaying XML with XSLT




With XSLT you can transform an XML document into HTML.




Displaying XML with XSLT

XSLT is the recommended style sheet language of XML.
XSLT (eXtensible Stylesheet Language Transformations) is far more sophisticated than CSS.
One way to use XSLT is to transform XML into HTML before it is displayed by the browser as demonstrated in these
examples:
View the XML file, the XSLT style sheet, and View the result.
Below is a fraction of the XML file. The second line links the XML file to the XSLT file:

<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="simple.xsl"?>
<breakfast_menu>
  <food>
    <name>Belgian Waffles</name>
    <price>$5.95</price>
    <description>
       two of our famous Belgian Waffles
    </description>
    <calories>650</calories>
  </food>
</breakfast_menu>
If you want to learn more about XSLT, find our XSLT tutorial on our homepage.




Transforming XML with XSLT on the Server

In the example above, the XSLT transformation is done by the browser, when the browser reads the XML file.
Different browsers may produce different result when transforming XML with XSLT. To reduce this problem the XSLT
transformation can be done on the server.
View the result.
Note that the result of the output is exactly the same, either the transformation is done by the web server or by the
web browser.
XML to HTML




This chapter explains how to display XML data as HTML.




Examples

Display XML data as an HTML table
Loads data from an XML file and displays it as an HTML table.




Display XML Data in HTML

In the last chapter, we explained how to parse XML and access the DOM with JavaScript.
In this example, we loop through an XML file (cd_catalog.xml), and display each CD element as an HTML table row:

<html>
<body>

<script type="text/javascript">
var xmlDoc=null;
if (window.ActiveXObject)
{// code for IE
xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
}
else if (document.implementation.createDocument)
{// code for Mozilla, Firefox, Opera, etc.
xmlDoc=document.implementation.createDocument("","",null);
}
else
{
alert('Your browser cannot handle this script');
}
if (xmlDoc!=null)
{
xmlDoc.async=false;
xmlDoc.load("cd_catalog.xml");

document.write("<table border='1'>");

var x=xmlDoc.getElementsByTagName("CD");
for (i=0;i<x.length;i++)
{
document.write("<tr>");
document.write("<td>");
document.write(
x[i].getElementsByTagName("ARTIST")[0].childNodes[0].nodeValue);
document.write("</td>");

document.write("<td>");
document.write(
x[i].getElementsByTagName("TITLE")[0].childNodes[0].nodeValue);
document.write("</td>");
document.write("</tr>");
}
document.write("</table>");
}
</script>

</body>
</html>
Try it yourself: Display XML data in an HTML table

Example explained

     •   We    check the browser, and load the XML using the correct parser
     •   We    create an HTML table with <table border="1">
     •   We    use getElementsByTagName() to get all XML CD nodes
     •   For   each CD node, we display data from ARTIST and TITLE as table data.
     •   We    end the table with </table>
For more information about using JavaScript and the XML DOM, visit our XML DOM tutorial.




Access Across Domains

For security reasons, modern browsers does not allow access across domains.
This means, that both the web page and the XML file it tries to load, must be located on the same server.
The examples on W3Schools all open XML files located on the W3Schools domain.
If you want to use the example above on one of your web pages, the XML files you load must be located on your
own server. Otherwise the xmlDoc.load() method, will generate the error "Access is denied".
Rancangan Jaringan Komputer
Rancangan Jaringan Komputer
Rancangan Jaringan Komputer
Rancangan Jaringan Komputer
Rancangan Jaringan Komputer
Rancangan Jaringan Komputer

More Related Content

What's hot

Fork forms library
Fork forms libraryFork forms library
Fork forms libraryYoniWeb
 
"Getting Started with XSLT" presentation slides
"Getting Started with XSLT" presentation slides"Getting Started with XSLT" presentation slides
"Getting Started with XSLT" presentation slidesRussell Ward
 
art2830 1st html tag presentation
art2830 1st html tag presentationart2830 1st html tag presentation
art2830 1st html tag presentationOscar Au
 
0016text[1].Txt.Xhtml
0016text[1].Txt.Xhtml0016text[1].Txt.Xhtml
0016text[1].Txt.XhtmlHOME
 

What's hot (12)

Lotus Notes Tips
Lotus Notes TipsLotus Notes Tips
Lotus Notes Tips
 
Fork forms library
Fork forms libraryFork forms library
Fork forms library
 
Form 1 Term 2 Week 4.3
Form 1   Term 2   Week 4.3Form 1   Term 2   Week 4.3
Form 1 Term 2 Week 4.3
 
"Getting Started with XSLT" presentation slides
"Getting Started with XSLT" presentation slides"Getting Started with XSLT" presentation slides
"Getting Started with XSLT" presentation slides
 
art2830 1st html tag presentation
art2830 1st html tag presentationart2830 1st html tag presentation
art2830 1st html tag presentation
 
hw4_specifications
hw4_specificationshw4_specifications
hw4_specifications
 
Dw Lesson01
Dw Lesson01Dw Lesson01
Dw Lesson01
 
Html tags
Html tagsHtml tags
Html tags
 
0016text[1].Txt.Xhtml
0016text[1].Txt.Xhtml0016text[1].Txt.Xhtml
0016text[1].Txt.Xhtml
 
php
phpphp
php
 
HTML 5 Basics Part Two
HTML 5 Basics Part TwoHTML 5 Basics Part Two
HTML 5 Basics Part Two
 
Creating a basic joomla
Creating a basic joomlaCreating a basic joomla
Creating a basic joomla
 

Viewers also liked

Bab ii seting ip dan dhcp server
Bab ii seting ip dan dhcp serverBab ii seting ip dan dhcp server
Bab ii seting ip dan dhcp serverCandra Adi Putra
 
Masalah komputer
Masalah komputerMasalah komputer
Masalah komputermira_saad
 
Materi workshop Mikrotik #3
Materi workshop Mikrotik #3Materi workshop Mikrotik #3
Materi workshop Mikrotik #3Putra Wanda
 
Mikrotik ppt
Mikrotik pptMikrotik ppt
Mikrotik ppt044249
 
Modul Workshop Mikrotik Bandwidth Management
Modul Workshop Mikrotik Bandwidth ManagementModul Workshop Mikrotik Bandwidth Management
Modul Workshop Mikrotik Bandwidth ManagementI Putu Hariyadi
 
Keselamatan Komputer
Keselamatan KomputerKeselamatan Komputer
Keselamatan Komputeramaniasraf
 
Diktat Praktikum Aplikasi Berbasis Jaringan
Diktat Praktikum Aplikasi Berbasis JaringanDiktat Praktikum Aplikasi Berbasis Jaringan
Diktat Praktikum Aplikasi Berbasis JaringanI Putu Hariyadi
 

Viewers also liked (12)

Dasar dasar mikrotik
Dasar dasar mikrotikDasar dasar mikrotik
Dasar dasar mikrotik
 
Bab ii seting ip dan dhcp server
Bab ii seting ip dan dhcp serverBab ii seting ip dan dhcp server
Bab ii seting ip dan dhcp server
 
Masalah komputer
Masalah komputerMasalah komputer
Masalah komputer
 
Makalah TIK - Kunjungan Warnet
Makalah TIK - Kunjungan WarnetMakalah TIK - Kunjungan Warnet
Makalah TIK - Kunjungan Warnet
 
Modul Mikrotik
Modul MikrotikModul Mikrotik
Modul Mikrotik
 
Materi workshop Mikrotik #3
Materi workshop Mikrotik #3Materi workshop Mikrotik #3
Materi workshop Mikrotik #3
 
Ppt Printer
Ppt PrinterPpt Printer
Ppt Printer
 
Mikrotik ppt
Mikrotik pptMikrotik ppt
Mikrotik ppt
 
Modul Workshop Mikrotik Bandwidth Management
Modul Workshop Mikrotik Bandwidth ManagementModul Workshop Mikrotik Bandwidth Management
Modul Workshop Mikrotik Bandwidth Management
 
MTCNA
MTCNAMTCNA
MTCNA
 
Keselamatan Komputer
Keselamatan KomputerKeselamatan Komputer
Keselamatan Komputer
 
Diktat Praktikum Aplikasi Berbasis Jaringan
Diktat Praktikum Aplikasi Berbasis JaringanDiktat Praktikum Aplikasi Berbasis Jaringan
Diktat Praktikum Aplikasi Berbasis Jaringan
 

Similar to Rancangan Jaringan Komputer (20)

Introduction to xml
Introduction to xmlIntroduction to xml
Introduction to xml
 
Xml material
Xml materialXml material
Xml material
 
Xml material
Xml materialXml material
Xml material
 
Xml material
Xml materialXml material
Xml material
 
Web programming xml
Web programming  xmlWeb programming  xml
Web programming xml
 
XML - The Extensible Markup Language
XML - The Extensible Markup LanguageXML - The Extensible Markup Language
XML - The Extensible Markup Language
 
Wp unit III
Wp unit IIIWp unit III
Wp unit III
 
Unit 2.2
Unit 2.2Unit 2.2
Unit 2.2
 
XML DTD Validate
XML DTD ValidateXML DTD Validate
XML DTD Validate
 
Introduction to xml schema
Introduction to xml schemaIntroduction to xml schema
Introduction to xml schema
 
Unit 2.2
Unit 2.2Unit 2.2
Unit 2.2
 
Introduction of xml and xslt
Introduction of xml and xsltIntroduction of xml and xslt
Introduction of xml and xslt
 
Xml PPT
Xml PPTXml PPT
Xml PPT
 
Web programming unit IIII XML &DOM NOTES BY BHAVSINGH MALOTH
Web programming unit IIII XML &DOM NOTES BY BHAVSINGH MALOTHWeb programming unit IIII XML &DOM NOTES BY BHAVSINGH MALOTH
Web programming unit IIII XML &DOM NOTES BY BHAVSINGH MALOTH
 
Xslt
XsltXslt
Xslt
 
Xslt
XsltXslt
Xslt
 
Transforming xml with XSLT
Transforming  xml with XSLTTransforming  xml with XSLT
Transforming xml with XSLT
 
Xml
XmlXml
Xml
 
Xml description
Xml descriptionXml description
Xml description
 
The Ebook Developer's Toolbox - ebookcraft 2016 - Sanders Kleinfeld
The Ebook Developer's Toolbox - ebookcraft 2016 - Sanders Kleinfeld The Ebook Developer's Toolbox - ebookcraft 2016 - Sanders Kleinfeld
The Ebook Developer's Toolbox - ebookcraft 2016 - Sanders Kleinfeld
 

More from Candra Adi Putra

More from Candra Adi Putra (20)

Puasa dan pemanfaatan media sosial
Puasa dan pemanfaatan media sosialPuasa dan pemanfaatan media sosial
Puasa dan pemanfaatan media sosial
 
Seting IP Manual in Windows, Mac OS X, Linux and Android
Seting IP Manual in Windows, Mac OS X, Linux and AndroidSeting IP Manual in Windows, Mac OS X, Linux and Android
Seting IP Manual in Windows, Mac OS X, Linux and Android
 
Mengenal Peralatan Jaringan
Mengenal Peralatan JaringanMengenal Peralatan Jaringan
Mengenal Peralatan Jaringan
 
Candra lab gis v 1
Candra lab gis v 1Candra lab gis v 1
Candra lab gis v 1
 
Layanan pelengkap twitter
Layanan pelengkap twitterLayanan pelengkap twitter
Layanan pelengkap twitter
 
Responsive web design
Responsive web designResponsive web design
Responsive web design
 
Budaya internet emoticon
Budaya internet emoticonBudaya internet emoticon
Budaya internet emoticon
 
Budaya internet flamewar
Budaya internet flamewarBudaya internet flamewar
Budaya internet flamewar
 
Budaya internet meme
Budaya internet memeBudaya internet meme
Budaya internet meme
 
Budaya internet troll
Budaya internet trollBudaya internet troll
Budaya internet troll
 
E commerce dengan php mysql.docx
E commerce dengan php mysql.docxE commerce dengan php mysql.docx
E commerce dengan php mysql.docx
 
Modul v pengenalan mikrotik
Modul  v pengenalan mikrotikModul  v pengenalan mikrotik
Modul v pengenalan mikrotik
 
ReactOS desktop
ReactOS desktopReactOS desktop
ReactOS desktop
 
Bab iv billing
Bab iv billingBab iv billing
Bab iv billing
 
Bab iii filesharing
Bab iii  filesharingBab iii  filesharing
Bab iii filesharing
 
Bab i dasar dasar jaringan
Bab i  dasar dasar jaringanBab i  dasar dasar jaringan
Bab i dasar dasar jaringan
 
Anatomi hasil pencarian Google
Anatomi hasil pencarian GoogleAnatomi hasil pencarian Google
Anatomi hasil pencarian Google
 
Best web app
Best web appBest web app
Best web app
 
Php modul1 dasar dasar php
Php modul1  dasar dasar phpPhp modul1  dasar dasar php
Php modul1 dasar dasar php
 
Ebook tutorial pemrograman android
Ebook tutorial pemrograman android Ebook tutorial pemrograman android
Ebook tutorial pemrograman android
 

Recently uploaded

Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 

Recently uploaded (20)

Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 

Rancangan Jaringan Komputer

  • 1. BAB III Memformat XML Viewing XML Files Raw XML files can be viewed in all major browsers. Don't expect XML files to be displayed as HTML pages. Viewing XML Files <?xml version="1.0" encoding="ISO-8859-1"?> - <note> <to>Tove</to> <from>Jani</from> <heading>Reminder</heading> <body>Don't forget me this weekend!</body> </note> Look at this XML file: note.xml The XML document will be displayed with color-coded root and child elements. A plus (+) or minus sign (-) to the left of the elements can be clicked to expand or collapse the element structure. To view the raw XML source (without the + and - signs), select "View Page Source" or "View Source" from the browser menu. Note: In Netscape, Opera, and Safari, only the element text will be displayed. To view the raw XML, you must right click the page and select "View Source" Viewing an Invalid XML File If an erroneous XML file is opened, the browser will report the error. Look at this XML file: note_error.xml Other XML Examples Viewing some XML documents will help you get the XML feeling. An XML CD catalog This is a CD collection, stored as XML data. An XML plant catalog This is a plant catalog from a plant shop, stored as XML data. A Simple Food Menu This is a breakfast food menu from a restaurant, stored as XML data. Why Does XML Display Like This? XML documents do not carry information about how to display the data. Since XML tags are "invented" by the author of the XML document, browsers do not know if a tag like <table> describes an HTML table or a dining table.
  • 2. Without any information about how to display the data, most browsers will just display the XML document as it is. In the next chapters, we will take a look at different solutions to the display problem, using CSS, XSLT and JavaScript. Displaying XML with CSS With CSS (Cascading Style Sheets) you can add display information to an XML document. Displaying your XML Files with CSS? It is possible to use CSS to format an XML document. Below is an example of how to use a CSS style sheet to format an XML document: Take a look at this XML file: The CD catalog Then look at this style sheet: The CSS file Finally, view: The CD catalog formatted with the CSS file Below is a fraction of the XML file. The second line links the XML file to the CSS file: <?xml version="1.0" encoding="ISO-8859-1"?> <?xml-stylesheet type="text/css" href="cd_catalog.css"?> <CATALOG> <CD> <TITLE>Empire Burlesque</TITLE> <ARTIST>Bob Dylan</ARTIST> <COUNTRY>USA</COUNTRY> <COMPANY>Columbia</COMPANY> <PRICE>10.90</PRICE> <YEAR>1985</YEAR> </CD> <CD> <TITLE>Hide your heart</TITLE> <ARTIST>Bonnie Tyler</ARTIST> <COUNTRY>UK</COUNTRY> <COMPANY>CBS Records</COMPANY> <PRICE>9.90</PRICE> <YEAR>1988</YEAR> </CD> . . . . </CATALOG> Formatting XML with CSS is not the most common method. W3C recommend using XSLT instead. See the next chapter.
  • 3. Displaying XML with XSLT With XSLT you can transform an XML document into HTML. Displaying XML with XSLT XSLT is the recommended style sheet language of XML. XSLT (eXtensible Stylesheet Language Transformations) is far more sophisticated than CSS. One way to use XSLT is to transform XML into HTML before it is displayed by the browser as demonstrated in these examples: View the XML file, the XSLT style sheet, and View the result. Below is a fraction of the XML file. The second line links the XML file to the XSLT file: <?xml version="1.0" encoding="ISO-8859-1"?> <?xml-stylesheet type="text/xsl" href="simple.xsl"?> <breakfast_menu> <food> <name>Belgian Waffles</name> <price>$5.95</price> <description> two of our famous Belgian Waffles </description> <calories>650</calories> </food> </breakfast_menu> If you want to learn more about XSLT, find our XSLT tutorial on our homepage. Transforming XML with XSLT on the Server In the example above, the XSLT transformation is done by the browser, when the browser reads the XML file. Different browsers may produce different result when transforming XML with XSLT. To reduce this problem the XSLT transformation can be done on the server. View the result. Note that the result of the output is exactly the same, either the transformation is done by the web server or by the web browser.
  • 4. Displaying XML with XSLT With XSLT you can transform an XML document into HTML. Displaying XML with XSLT XSLT is the recommended style sheet language of XML. XSLT (eXtensible Stylesheet Language Transformations) is far more sophisticated than CSS. One way to use XSLT is to transform XML into HTML before it is displayed by the browser as demonstrated in these examples: View the XML file, the XSLT style sheet, and View the result. Below is a fraction of the XML file. The second line links the XML file to the XSLT file: <?xml version="1.0" encoding="ISO-8859-1"?> <?xml-stylesheet type="text/xsl" href="simple.xsl"?> <breakfast_menu> <food> <name>Belgian Waffles</name> <price>$5.95</price> <description> two of our famous Belgian Waffles </description> <calories>650</calories> </food> </breakfast_menu> If you want to learn more about XSLT, find our XSLT tutorial on our homepage. Transforming XML with XSLT on the Server In the example above, the XSLT transformation is done by the browser, when the browser reads the XML file. Different browsers may produce different result when transforming XML with XSLT. To reduce this problem the XSLT transformation can be done on the server. View the result. Note that the result of the output is exactly the same, either the transformation is done by the web server or by the web browser.
  • 5. XML to HTML This chapter explains how to display XML data as HTML. Examples Display XML data as an HTML table Loads data from an XML file and displays it as an HTML table. Display XML Data in HTML In the last chapter, we explained how to parse XML and access the DOM with JavaScript. In this example, we loop through an XML file (cd_catalog.xml), and display each CD element as an HTML table row: <html> <body> <script type="text/javascript"> var xmlDoc=null; if (window.ActiveXObject) {// code for IE xmlDoc=new ActiveXObject("Microsoft.XMLDOM"); } else if (document.implementation.createDocument) {// code for Mozilla, Firefox, Opera, etc. xmlDoc=document.implementation.createDocument("","",null); } else { alert('Your browser cannot handle this script'); } if (xmlDoc!=null) { xmlDoc.async=false; xmlDoc.load("cd_catalog.xml"); document.write("<table border='1'>"); var x=xmlDoc.getElementsByTagName("CD"); for (i=0;i<x.length;i++) { document.write("<tr>"); document.write("<td>"); document.write( x[i].getElementsByTagName("ARTIST")[0].childNodes[0].nodeValue); document.write("</td>"); document.write("<td>"); document.write( x[i].getElementsByTagName("TITLE")[0].childNodes[0].nodeValue); document.write("</td>"); document.write("</tr>");
  • 6. } document.write("</table>"); } </script> </body> </html> Try it yourself: Display XML data in an HTML table Example explained • We check the browser, and load the XML using the correct parser • We create an HTML table with <table border="1"> • We use getElementsByTagName() to get all XML CD nodes • For each CD node, we display data from ARTIST and TITLE as table data. • We end the table with </table> For more information about using JavaScript and the XML DOM, visit our XML DOM tutorial. Access Across Domains For security reasons, modern browsers does not allow access across domains. This means, that both the web page and the XML file it tries to load, must be located on the same server. The examples on W3Schools all open XML files located on the W3Schools domain. If you want to use the example above on one of your web pages, the XML files you load must be located on your own server. Otherwise the xmlDoc.load() method, will generate the error "Access is denied".