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

From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 

Recently uploaded (20)

From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 

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".