|
ds are set by the World Wide Web Consortium (W3C).
Internet Explorer 5.0 has the following XML support:
- Viewing of XML documents
- Full support for W3C DTD standards
- XML embedded in HTML as Data Islands
- Binding XML data to HTML elements
- Transforming and displaying XML with XSL
- Displaying XML with CSS
- Access to the XML DOM
Internet Explorer 5.0 also has support for Behaviors:
- Behaviors is a Microsoft-only technology
- Behaviors can separate scripts from an HTML page.
- Behaviors can store XML data on the client''''s disk.
Examples of all these features are given in the next chapters of this web site.
Viewing XML Files
Raw XML files can be viewed in Mozilla Firefox, IE 5.0+ and in Netscape 6.
However, to make XML documents to display like nice web pages, you will have to add some display information.
Viewing XML Files
In Mozilla Firefox and IE 5.0+:
Click on a link to an XML file, type the direct URL in the address bar, or double-click on the name of an XML file in a folder. 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.
In Netscape 6:
Open the XML file (via a link or URL), then right-click in XML file and select "View Page Source". The XML document will then be displayed with color-coded root and child elements.
Look at this XML file: note.xml
Note: Do not expect XML files to be formatted like HTML documents!
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 my father''''s CD collection, stored as XML data (old and boring titles I think.... :-)).
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, XSL, JavaScript, and XML Data Islands.
Displaying XML with CSS
With CSS (Cascading Style Sheets) you can add display information to an XML document.
Displaying your future XML files with CSS?
Would you use CSS to format your future XML files? No, we don''''t think so! But we could not resist giving it a try:
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, <?xml-stylesheet type="text/css" href="cd_catalog.css"?>, 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>
We DO NOT believe that formatting XML with CSS is the future of the Web. Even if it looks right to use CSS this way, we DO believe that formatting with XSL will be the new standard (as soon as all main browsers support it).
Creating your future Homepages with XML?
Will you be writing your future Homepages in XML? No, we don''''t think you will! But we could not resist giving it a try : A homepage written in XML.
We DO NOT believe that XML will be used to create future Homepages.
Displaying XML with XSL
With XSL you can add display information to your XML document.
Displaying XML with XSL
XSL is the preferred style sheet language of XML.
XSL (the eXtensible Stylesheet Language) is far more sophisticated than CSS. One way to use XSL is to transform XML into HTML before it is displayed by the browser as demonstrated in these examples:
If you have Netscape 6 or IE 5 or higher you can view the XML file and the XSL style sheet.
View the result in IE 6
View the result in IE 5
Below is a fraction of the XML file, with an added XSL reference. The second line, <?xml-stylesheet type="text/xsl" href="simple.xsl"?>, links the XML file to the XSL 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 XSL, please visit our XSL tutorial.
XML in Data Islands
With Internet Explorer 5.0 and higher, XML can be embedded within HTML pages in Data Islands.
XML Embedded in HTML
The unofficial <xml> tag is used to embed XML data within HTML.
XML data can be embedded directly in an HTML page like this:
<xml id="note">
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don''''t forget me this weekend!</body>
</note>
</xml>
Or a separate XML file can be embedded like this:
<xml id="note" src="note.xml">
</xml>
Note that the <xml> tag is an HTML element, not an XML element.
Data Binding
Data Islands can be bound to HTML elements (like HTML tables).
In the example below, an XML Data Island with an ID "cdcat" is loaded from an external XML file. An HTML table is bound to the Data Island with a data source attribute, and finally the tabledata elements are bound to the XML data with a data field attribute inside a span.
<html>
<body>
<xml id="cdcat" src="cd_catalog.xml"></xml>
<table border="1" datasrc="#cdcat">
<tr>
<td><span datafld="ARTIST"></span></td>
<td><span datafld="TITLE"></span></td>
</tr>
</table>
</body>
</html>
If you are running IE 5.0 or higher, you can try it yourself.
With IE 5.0 and higher you can also view the external XML file.
Also try this example, demonstrating <thead>, <tbody>, and <tfoot>.
The Microsoft XML Parser
To read and update - create and manipulate - an XML document, you need an XML parser.
Using the XML parser
The Microsoft XML parser comes with Microsoft Internet Explorer 5.0.
Once you have installed IE 5.0, the parser is available to scripts, both inside HTML documents and inside ASP files. The parser features a language-neutral programming model that supports:
|