XML with Data Source Object

What is XML Data Source Object?

XML Data Source Object is a Microsoft Active X object built into the web browser so we can use ActiveX control to extract data from the XML code embedded directly in the HTML file and the external XML file using data binding into HTML web pages.

Data islands

  • XML code is embedded in an HTML document to create data islands.
  • The file should be saved with .html or .htm extension.
Data islands are created with two methods:

1. Explicit method: Embedding data directly.

Syntax:
<XML ID=“xmlID”>
     <!-- XML data-->
</XML>

2. Implicit method: Embedding XML data with reference to external XML file.
Syntax:
<XML ID=“xmlID” SRC=“filename.xml”></XML>

  • The DSO object is implicitly created when we use a XML data island.
  • To extract data from external data file use the HTML tags.
  • <IMG>, <LABLE>, <TABLE>
  • Two attributes are very important along with html tags.
  • a) DATASRC: Specifies the source of data.
    b) DATAFLD: Specifies the field from where the data is to be displayed.

Example : Write a program to display content in table using XML-DSO

<html>
<head>
</head>
     <body>
     <xml id="xml">
     <table datasrc="#xml">
          <thead>
               <th>Name</th>
               <th>Sex</th>
          </thead>
          <tr>
               <td><div datafld="name"></div></td>
               <td><div datafld="sex"></div></td>
          </tr>
     </table>
     <db>
          <member>
               <name>BOB </name>
               <sex>male</sex>
          </member>
     </db>
     </xml>
     </body>
</html>


Output:
bob xml dso

XML-DSO object is used to load external XML document.

The steps to do this are as follows:
  • Create and initialize XML-DSO object.
  • Syntax:
    <OBJECT ID=“SomeID CLASSID=CLSID”></OBJECT>
  • Load the external XML file in HTML page using the XMLDSO. We have to use Javascript in the <HEAD> section of HTML page.
  • Extract data from loaded XML file through HTML tags using DATASRC and DATAFLD.