Home   |  Viewing problem solution  |  About me


 

XML - Live Example

 
One of the biggest problem for a newbie XML-programmer (like me, fortunately), is that he doesn't see the output of his xml file in the readable format. As I have already said, that XML describes the structure of the text and not how it should be displayed. So when you create a file abc.xml & view it in Internet Explorer or any other web browser (that supports XML, of course), all you see is:

<?xml version="1.0" ?>
- <Authors>
- <Author>
  <au_id>172-32-1176</au_id>
  <au_lname>White</au_lname>
  <au_fname>Johnson</au_fname>
  </Author>
- <Author>
  <au_id>213-46-8915</au_id>
  <au_lname>David</au_lname>
  <au_fname>Duright</au_fname>
  </Author>
- <Author>
  <au_id>238-95-7766</au_id>
  <au_lname>Macmillan</au_lname>
  <au_fname>Harold</au_fname>
  </Author>
  </Authors>

which I think is not at all readable and desirable. So to solve the above problem you can use a standard called "Data Island". A Data Island is nothing but a XML tag (denoted by <XML>) in an ordinary HTML file. The Data Island can be created in one of the two ways.

1. The first method is - specify the file name with SRC attribute in the <XML> tag, like:

<XML ID="dsoData" SRC="abc.xml">

Since the abc.xml file contains the XML data (remember, only structure & not the presentation), nothing is shown on the screen. We will have to follow another few steps to make the data visible on the screen.

2. The second method is - write down the entire XML code in the HTML file itself, as part of it.

Kindly look at the following example for the complete view. The example is using the second method for creating Data Island, but you can use the first one also. Process of viewing XML data through the HTML controls is called Binding.

Binding to an XML Data Island



172-32-1176 White Johnson 213-46-8915 David Duright 238-95-7766 Macmillan Harold



Place the following code in the HTML file to see the above output,

<XML ID="dsoData">
    <Authors>
        <Author>
            <au_id>172-32-1176</au_id>
            <au_lname>White</au_lname>
            <au_fname>Johnson</au_fname>
        </Author>
        <Author>
            <au_id>213-46-8915</au_id>
            <au_lname>David</au_lname>
            <au_fname>Duright</au_fname>
        </Author>
        <Author>
            <au_id>238-95-7766</au_id>
            <au_lname>Macmillan</au_lname>
            <au_fname>Harold</au_fname>
        </Author>
    </Authors>
</XML>

<table DATASRC="#dsoData">
    <TR>
        <td><INPUT TYPE="TEXT" DATAFLD="au_id" size="20"></INPUT></td>
        <td><INPUT TYPE="TEXT" DATAFLD="au_lname" size="20"></INPUT></td>
        <td><INPUT TYPE="TEXT" DATAFLD="au_fname" size="20"></INPUT></td>
    </TR>
</table>

All rights reserved. Copyright © 1999 - . Krishna Kumar Khatri.
Best viewed with Microsoft IE 6 or later, under 800x600 resolution with True Color (24-bit).