Using the XML DSO


You also can use the XML DSO that comes with Internet Explorer to handle data in XML format. We'll see more on XML in Chapter 22, "XML and XSLT." In XML documents, you create your own tags and elements. In this case, I'll enclose all our data in an element I'll call <EMPLOYEES> , and enclose each record in an element I'll name <ITEM> . To name the fields in each record, you create elements of the same name, such as <NAME> for the Name field, <ID> for the ID field, and so on. Given all that, here's how I store our employee data as an XML document, data.xml:

(data.xml on the web site)
 <?xml version="1.0"?>  <EMPLOYEES>      <ITEM>          <NAME>Frank</NAME>          <ID>2314</ID>          <DEPARTMENT>Shipping</DEPARTMENT>          <TITLE>Packer</TITLE>          <HIRE_DATE>9-2-2003</HIRE_DATE>      </ITEM>      <ITEM>          <NAME>Martin</NAME>          <ID>2315</ID>          <DEPARTMENT>Packing</DEPARTMENT>          <TITLE>Programmer</TITLE>          <HIRE_DATE>9-2-2003</HIRE_DATE>      </ITEM>      <ITEM>          <NAME>Tom</NAME>          <ID>2316</ID>          <DEPARTMENT>Shipping</DEPARTMENT>          <TITLE>Packer</TITLE>          <HIRE_DATE>9-2-2003</HIRE_DATE>      </ITEM>      <ITEM>          <NAME>Henry</NAME>          <ID>2317</ID>          <DEPARTMENT>Shipping</DEPARTMENT>          <TITLE>Packer</TITLE>          <HIRE_DATE>9-2-2003</HIRE_DATE>      </ITEM>      <ITEM>          <NAME>Paula</NAME>          <ID>2318</ID>          <DEPARTMENT>Shipping</DEPARTMENT>          <TITLE>Packer</TITLE>          <HIRE_DATE>9-2-2003</HIRE_DATE>      </ITEM>  </EMPLOYEES> 

The XML DSO is actually a Java applet that comes with the Internet Explorer. You can create a DSO with that applet using the <APPLET> element like this, where I'm creating an XML DSO named dso1 and filling that DSO with the data in data.xml:

 <APPLET CODE="com.ms.xml.dso.XMLDSO.class"      ID="dso1" WIDTH="0" HEIGHT="0" MAYSCRIPT="true">      <PARAM NAME="URL" VALUE="data.xml">  </APPLET> 

Now we can use this DSO as we have the MSHTML and TDC DSOs. Here's some code that puts the XML DSO to work, binding the data in data.xml to elements in a web page:

(Listing 17-09.html on the web site)
 <HTML>      <HEAD>          <TITLE>              Using the XML Data Source Control          </TITLE>      </HEAD>      <BODY>          <H1>              Using the XML Data Source Control          </H1>          <APPLET CODE="com.ms.xml.dso.XMLDSO.class"              ID="dso1" WIDTH="0" HEIGHT="0" MAYSCRIPT="true">             <PARAM NAME="URL" VALUE="data.xml">          </APPLET>          Name: <SPAN DATASRC="#dso1" DATAFLD="NAME"></SPAN>          <BR>          ID: <SPAN DATASRC="#dso1" DATAFLD="ID"></SPAN>          <BR>          Department: <SELECT DATASRC="#dso1"              DATAFLD="DEPARTMENT" SIZE=1>              <OPTION VALUE="Shipping">Shipping              <OPTION VALUE="Packing">Packing              <OPTION VALUE="Accounting">Accounting              <OPTION VALUE="Billing">Billing          </SELECT>          <BR>          Title: <SPAN DATASRC="#dso1" DATAFLD="TITLE"></SPAN>          <BR>          Date hired: <SPAN DATASRC="#dso1" DATAFLD="HIRE_DATE"></SPAN><P>          <BR>          <BUTTON ONCLICK="dso1.recordset.MoveFirst()">&lt;&lt;</BUTTON>           <BUTTON ONCLICK="if (!dso1.recordset.BOF)              dso1.recordset.MovePrevious()">&lt;</BUTTON>          <BUTTON ONCLICK="if (!dso1.recordset.EOF)              dso1.recordset.MoveNext()">&gt;</BUTTON>          <BUTTON ONCLICK="dso1.recordset.MoveLast()">&gt;&gt;</BUTTON>      </BODY>  </HTML> 

The results in the Internet Explorer are just like what you see in Figure 17.7, except that we're using a different DSO; and in this case, we've stored our data in XML format, not text and not HTML.

You also can bind the XML DSO to an HTML table, just as with the MSHTML and TDC DSOs. Here's an example that does that in the Internet Explorer:

(Listing 17-10.html on the web site)
 <HTML>      <HEAD>          <TITLE>              Using the XML Data Source Control and a Table          </TITLE>      </HEAD>      <BODY>          <H1>              Using the XML Data Source Control and a Table          </H1>          <APPLET CODE="com.ms.xml.dso.XMLDSO.class"              ID="dso1" WIDTH="0" HEIGHT="0" MAYSCRIPT="true">              <PARAM NAME="URL" VALUE="data.xml">          </APPLET>          <TABLE DATASRC="#dso1" CELLSPACING="10">              <THEAD>                  <TR>                      <TH>Name</TH>                      <TH>ID</TH>                      <TH>Department</TH>                      <TH>Title</TH>                      <TH>Date hired</TH>                  </TR>              </THEAD>               <TBODY>                   <TR>                      <TD><SPAN DATAFLD="NAME" DATAFORMATAS="HTML">                          </SPAN></TD>                      <TD><SPAN DATAFLD="ID" DATAFORMATAS="HTML">                          </SPAN></TD>                  <TD><SPAN DATAFLD="DEPARTMENT"                       DATAFORMATAS="HTML"></SPAN></TD>                  <TD><SPAN DATAFLD="TITLE"                       DATAFORMATAS="HTML"></SPAN></TD>                  <TD><SPAN DATAFLD="HIRE_DATE" DATAFORMATAS="HTML">                       </SPAN></TD>                  </TR>              </TBODY>          </TABLE>      </BODY>  </HTML> 

As before, the results are just like what you see in Figure 17.8, except that we're using a different DSO; and in this case, we've stored our data in XML format, not text and not HTML.



Inside Javascript
Inside JavaScript
ISBN: 0735712859
EAN: 2147483647
Year: 2005
Pages: 492
Authors: Steve Holzner

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net